-
Triangle Numbers: Using the Boom! program as a model,
write a Java Applet that prints the first N triangle numbers to
System.out.println.
Triangle Numbers are integers which result by arranging
objects in a triangle, such as 1, 3, 6 or 10 objects:
x
x x x
x x x x x x
x x x x x x x x x x
1 3 6 10
Generate Triangle Numbers as follows:
- Set triangleNumber to 0, index to 1.
- Increment triangleNumber by index, and then index by 1.
- Print triangleNumber and repeat the increment step, if index
is less than N.
Place your finished Triangle.java, Traingle.class and Triangle.html
in your public_html so I may grade it.
- Fibonacci Numbers: Using the above program as a model,
generate and print the first N Fibonacci Numbers.
The Fibonacci Numbers is the sequence of integers: 1, 1, 2, 3,
5, 8, etc, where each number in the sequence is the sum of
the previous two numbers in the sequence.
One method to generate the Fibonacci numbers is as follows:
- Set oldFibonacci to 0, thisFibonacci to 1, index to 0.
- Set newFibonacci to the sum of thisFibonacci and oldFibonacci.
- print out thisFibonacci, move thisFibonacci to oldFibonacci
then move newFibonacci to thisFibonacci.
- Increment count, and if it is less than N, return to step 2.
Place your finished Fibonacci.java, Fibonacci.class and Fibonacci.html
in your public_html so I may grade it.
- Boom for Windows: Modify the Boom program to output to the
applet window, rather than to System.out.
You will need the following modifications:
- Move the count-down code into the paint method. Each time the
screen is painted, you will re-run the count-down code to generate
the screen.
- To use drawString, you will need to change the integer count
into a string. Use String.valueOf(count).
- The second and third arguments to drawString are the x and y
coordinates at which the string is drawn. You will have to increment
y by a certain number of pixels to have the count-down descend the
screen.
- If you want, use gc.setColor(Color.red) to paint
Boom! in red.
Place your finished Boom.java, Boom.class and Boom.html
in your public_html so I may grade it.