There are three problems in this homework.

Problem A

Write a Java class ClockArithProgression that extends the Progression class (from Section 2.2) in the following way. A ClockArithProgression is similar to an arithmetic progression, and is characterized by two positive integers inc and p. The progression defined by these integers is [ 0 mod p, (0 + inc) mod p, (0 + inc + inc) mod p, (0 + inc + inc + inc) mod p, ...]. Here, (x mod y) denotes the remainder when x is divided by y.

For example, if p is 12, and inc is 5, then the progression is [ 0, 5, 10, 3, 8, 1, 6, ...]. Notice that such a progression can also be defined in the following way. Its first element is 0. If the current element of the proression is cur, then its next element is (cur + inc) mod p.

You should use a default constructor that sets 5 and 12 as the values of inc and p, respectively. You should also define a parametric constructor that sets inc and p to the pair of numbers given as input to the constructor. One requirement is that you should not override the printProgression method in the Progression class, but it should nevertheless work correctly on a ClockArithProgression object. For convenience of testing, I have placed the code for the Progression class here in the file (4 points)

It might help to review the Arithmetic Progression class in Section 2.2, which can also be found here.

Problem B

As reviewed in class, the last line in the main method (which resides in the file here ) does not correctly print the first ten elements of a Fibonacci Progression. Modify the FibonacciProgression class to fix this error, without overriding the printProgression method from the class Progression. (3 points)

Problem C

This java program performs an array reference that is out of bounds in one of the executions of the assignment statement

sum = sum + myArray[i];
If you run the program, it throws an exception when this out of bounds reference happens.

Wrap that assignment statement within a try-catch block so that the resulting program catches that exception and prints the following message: "You are accessing an index that is out of bounds!". (3 points)

For this problem, it will help immensely if you attend your discussion Section on Thursday (9/12). Note that to solve this problem you do not have to define and throw an exception.

Submission Instructions

The source code for this homework needs to be submitted into a dropbox called Homework2 in ICON. Problems A and B are in the same package, so you can submit all the .java files in that package as your combined solution to these problems. For Problem C, you need to submit the .java files in package fall13hw2c: most likely, this will be the file, suitably modified. The homework is due Wednesday, September 18, at 11:59 pm.