Assignment 2: 1/83, 11/84 (textbook)

This assignment is due Tuesday January 26 11:15am-12:30pm in class.

Effective this assignment you will turn in two parts:

• due Thursday January 21 in class: analysis of the problem and design of your solution. A description of how you intend to approach (or solve) the problems in the homework. (If you turn this in on Thursdays you will get 10% of the assignment. If you don't turn it in on time you lose 10% of the assignment.)

• due before Tuesday January 26 noon: the source code for the two problems by e-mail. (Turn this in for 90% of the total number of points for the assignment. The rest 10% is collected on Thursdays by turning in the analysis and design).

See notes on submitting assignments by e-mail.

Details of the assignment:

1/83: Problem 1, page 83, in your textbook.

Call your source code file `Division.java`.

When you first learned to divide, you expressed answers using a quotient and a remainder rather than a fraction or decimal quotient. For example, if you divided 9 by 2, you gave your answer as 4 remainder 1. Write a program that takes two integers as inputs and displays their quotient and remainder as outputs. Do not assume that the integers are entered in any order, but be sure to divide the larger integer by the smaller integer.

Do the division by using only - (subtraction). Do not use the operators / and % that Java provides.

The program needs to have a `BreezyGUI` interface similar to (for example) the one used by Case Study 4.2 (the two labels should both read `Operand` and the button `Divide`). When the user pushes `Divide` the program should take the two integer operands, decide which one is bigger, and produce the results of the division of the largest one by the smallest one in a `messageBox`. If the two operands are equal the problem is elementary.

Do not attempt any processing when the user enters negative numbers and post an error message when that happens.

Hints: do it by hand a few times and notice the repetitive aspect of it. Use a `while` loop. For the ambitious: use a `for` loop.

11/84: Problem 11, page 84, in your textbook.

Call your source code file `Interest.java`.

John has \$500 to invest. Sue knows of a mutual fund plan that pays 10% interest, compunded quarterly (that is, every 3 months, the principal is multiplied by the 2.5% and the result is added to the principal). Write a program that will tell John how much money will be in the fund after 20 years. Make the program general; that is, it should take as inputs the interest rate, the initial principal, and the numbers of years to stay in the fund. The output should be a table whose columns are the year number, the principal at the beginning of the year, the interest earned, and the principal at the end of the year.

The program needs to have an interface similar to Case Study 4.5 on page 80 of your text (which solves a problem with a similar structure).

Hints: use a `for` loop, since the number of iterations is known in advance.

In your programs, please use a consistent style and make sure that we can clearly identify you, your lab section and the assignment by looking at your source code. Insert a comment block of the following form at the beginning of your programs, as you have done in A201:

```/*  Name:            Your Name