Project 1 - Math 599: Java Programming

Assigned: June 30, 1997.
Due: July 3, 1997.

  1. 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:
    1. Set triangleNumber to 0, index to 1.
    2. Increment triangleNumber by index, and then index by 1.
    3. 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.

  2. 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:

    1. Set oldFibonacci to 0, thisFibonacci to 1, index to 0.
    2. Set newFibonacci to the sum of thisFibonacci and oldFibonacci.
    3. print out thisFibonacci, move thisFibonacci to oldFibonacci then move newFibonacci to thisFibonacci.
    4. 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.

  3. Boom for Windows: Modify the Boom program to output to the applet window, rather than to System.out.

    You will need the following modifications:

    1. 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.
    2. To use drawString, you will need to change the integer count into a string. Use String.valueOf(count).
    3. 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.
    4. 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.