Assignment 2, due Aug 28

Part of the homework for CS:2820, Fall 2015
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

On every assignment, write your name legibly as it appears on your University ID card! Homework is due on paper at the start of class on the day indicated (usually Friday). Exceptions will be made only by advance arrangement (excepting "acts of God"). Late work must be turned in to the TA's mailbox (ask the CS receptionist in 14 MLH for help). Never push homework under someone's door!

  1. Background: Remember this little function from homework 1?
    function f( i )
       if i < 3
          return i
       else
          return f( i - 1 ) + f( i - 2 ) + f( i - 3 )
    

    A Question: Write a Java program that computes and outputs all successive members of this sequence up to the point that the values exceed 1000, one number per line. The sequence begins 0, 1, 2, 3, 6, 11, 20, and here is the modified hello world code from the lecture on Aug 27:

    public class HelloWorld {
        public static void main(String[] args) { // it starts here
            int i = 0;
            int j = 1;
            int k = 0;
            System.out.println("Hello, World");
            while (true) {
                System.out.println(""+i);
                k = i + j;
                i = j;
                j = k;
            }
        }
    }
    

    The above code contains leftovers from the trivial hello-world program (for example, the class name itself and the first line of output. A more appropriate class name might be something like sequence?

    Easily legible handwritten code is acceptable, but your code will be graded on cosmetic issues such as clean indenting and spacing, sensible variable names, lack of inappropriate comments and presence of appropriate comments. This is a trivial program, do not over document it, but please, do claim authorship.

    You need not run your code, but of course, if you run it, you will gain some assurance of its correctness. (2.0 points)

  2. A short question: What is the difference between a static method and a static field of a class. (0.5 points)

  3. A short question: What is the difference between /**comments**/ and /*comments*/? (0.5 points)