Before you attempt this project make sure you download the smaller one java SDK, (52 MB) called Java(TM) 2 SDK, Standard Edition 1.4.2_08. To make things easier, when you install Java click the Change button and install it into C:\Java, then you should build your source code and compile from:
C:\Java\bin\
Using notepad, create a file named SquareApp.java and type in the following code:
/**
* The SquareApp class implements an application that
* displays a Square made of asterisks to the standard output.
*/
public class SquareApp {
public static void main(String[] args) {
// Display A Square
int x, y;
for (x = 0; x < 10; x ++) { // Loop controls number of lines
for (y = 0; y < 10; y ++) { // number of * printed
System.out.print("* ");
}
System.out.println("");
}
}
}
Once you get your command prompt into the proper directory, compile with the command:
javac SquareApp.java
Run your program with:
java SquareApp
NEXT Step:
Now use the same process to create a second application called TriangleApp.
Use the following code:
/**
* The Triangle1App class implements an application that
* displays a triangle made of asterisks to the standard output.
*/
public class Triangle1App {
public static void main(String[] args) {
// Display A Triangle
int x, y;
for (x = 0; x < 10; x ++) {// controls number of lines printed
for (y = 0; y < x; y ++) { // number of * printed
System.out.print("* ");
}
System.out.println("");
}
}
}
Once you get your command prompt into the proper directory, compile with the command:
javac Triangle1App.java
Run your program with:
java Triangle1App
The program should print a triangle like this:
*
* *
* * *
Notice that the only line that changes between to the two programs is the one highlighted in bold. This line controls how many times the inner loop prints out asterisks. Your mission is to get these programs to work, that is worth 5 points of extra credit. Also, if you can, rewrite the triangle program to print out a triangle in 3 different patterns, call them Triangle2App.java, Triangle3App.java and Triangle4App.java.
***
**
*and...
*
**
***and...
***
**
*
Each of the above patterns is worth 5 points of extra credit. For each one, upload the TriangleApp#.java file. If you get all 4 working, you get 20 points extra credit.