First Exercise

As in the programming exercise from last week, the first exercise involves question 2 from the written part of the first test. In question 2, you were given 3 classes: A.java, B.java and C.java.
For this programming exercise, they have been changed a little. Where changes have been made, you'll see // NEW Here they are:

These 3 classes are used in the program Output.java. It too has been changed a little from last week. Look for // NEW. In Output.java, you are asked to copy and paste in, one after the other, 27 pieces of code to complete the program, but only after having written in what you think the output will be. These 27 code blocks are labelled a - q and q' - z. The parts a - p are the same as last week and will have the same answer as last week. You should considered parts a - z independently of one another; always delete the previous one before pasting in the new one. And always commit yourself to an answer/output before compiling and running the program with the new code. This gives you a chance to compare what actually happens with what you thought would happen and then try to understand any differences. ANOTHER DIFFERENCE with last week: before, you were asked just to write in "compiletime error" or "runtime error" if you thought an error would occur; this time, you are asked to be more specific - approximately which compiletime error message would you get and approximately which exception would be thrown at runtime.

You won't submit this exercise. For feedback, ask the TA during the lab if you cannot figure out why Output.java is producing a particular output or ask your instructor in class/office hour. But, of course, try a bit to figure things out first.

Second Exercise

Here are a couple of short recursion exercises.

Here is a class of static methods.

You can submit this program using the following commend:

    % submit 1030 Exercise6 RecursiveMethods.java