Assignment #4: Objects and Classes
Winter 1999
(To be completed for your lab period February 1/2)
Objective: To learn the fundamentals of object-based programming.
This part is optional and will not be marked. Doing it will help you understand the differences between objects and static methods.
Modify your assignment #3 to use an Account object. The object will contain all of the state variables about the account, such as its balance, lowest balance since interest was applied, and the interest rate. Remember to keep these variables private to the class.
Write a class Rational for peforming arithmetic with fractions. A rational object uses an integer for the numerator and another integer for the denominator.
Write the following methods for the Rational class:
Write a short main routine which accesses these methods. Like the bank account program, it should remember one rational number and ask you if you want to add, subtract, multiple, divide, reduce, print, or evaluate to this rational number.
For +-*/, it must prompt you for the numerator and denominator of another rational number to operate with.
The reduce() method should only remove common factors; it does not print out any result. Instead, the print option will call the toString() method and print the result. The evaluate() method returns the value of fraction as a double, and the main program should print this result.