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:

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.

Comments

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 
    Username:        Your Username 
    Lab Section:     Your Lab Section #, Meeting Time and Place
    Lab Instructor:  Your Lab Instructor's Name or Username 
    Assignment:      Number and Due Date of The Assignment 
*/
You may want to write the first four items on the disk label anyway.

There will be an extra-problem, for the ambitious, that will be posted in the lab notes after the lecture on Tuesday. It's an optional problem, for which you will receive feedback if you turn it in, but which will not be part of this assignment per se.


If you have any questions please let us know.