There are three problems in this homework. For each problem, if your program resides
in a single file, submit that file into the dropbox in ICON named Homework2; if
your program resides in multiple files, submit a zip of those files or of the
directory containing those files.
Problem 1
Write a short program that takes as inputs three integers (which we will denote as
a, b, and c) from the Java console, and outputs the string
"Yes" if any two of the numbers add up to the third, and "No" otherwise. (So the program
should output "Yes" if a and b add up to c, or if a
and c add up to b, or if b and c add up to a.
You will need to read Section 1.6, which we very briefly touched upon, to see how to read from the
console. (3 points)
Problem 2
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 Progression.java. (4 points)
It might help to review the Arithmetic Progression class in Section 2.2.
Problem 3
Write a Java program that performs an array reference that is possibly out of bounds,
and if it is out of bounds, the program catches that exception and prints the following
message: "Don't try buffer overflow attacks in Java!". (3 points)
For this problem, it will help immensely if you attend your discussion Section on
Thursday (8/30).