COMP 170    -    PROGRAM VII  (Fraction Calculator)

Due:  Saturday, 18 March 2000

Design, test, and run a project, FractionCalculator, which contains a class, Fraction,  that defines Fraction objects and several instance methods corresponding to Fraction arithmetic operations (addition, multiplication, division, reduction to lowest terms).   (For the sake of simplicity, you may assume that the fractions are all non-negative numbers.)  You will also design a class (or client), FractionCalculator, containing the main method which asks the user for input and performs standard arithmetic operations upon the fractions, and then prints the results.
 

Sample dialogue:

Welcome to Antoine Roquentin's fraction calculator.

Choose from the following menu (type the character of your choice):
A:  to add two fractions.
M:  to multiply two fractions.
D:  to divide two fractions.
R:  to reduce a fraction to lowest terms.
X:  to terminate this session.
A
Type your first fraction (Numerator on first line;  Denominator on next line):
13
2
Type your second fraction:
6
9
Thank you.  The sum of 13/2 and 6/9 is 43/6.

Choose from the following menu (type the character of your choice):
A:  to add two fractions.
M:  to multiply two fractions.
D:  to divide two fractions.
R:  to reduce a fraction to lowest terms.
X:  to terminate this session.
R
Type your fraction (Numerator on first line;  Denominator on next line):
400
1200
Thank you. The reduced form of 400/1200 is 1/3.

Choose from the following menu (type the character of your choice):
A:  to add two fractions.
M:  to multiply two fractions.
D:  to divide two fractions.
R:  to reduce a fraction to lowest terms.
X:  to terminate this session.
M
Type your first fraction (Numerator on first line;  Denominator on next line):
8
27
Type your second fraction:
3
4
Thank you.  The product of 8/27 and 3/4 is 2/9.

Choose from the following menu (type the character of your choice):
A:  to add two fractions.
M:  to multiply two fractions.
D:  to divide two fractions.
R:  to reduce a fraction to lowest terms.
X:  to terminate this session.
X
Thank you for using the Fraction Calculator!  Type any character to end session.

Notes:

What to submit:

Electronic submission of the files:   FractionCalculator.java and Fraction.java.
 
 

The world is divided into two classes, those who believe the incredible, and those who do the improbable.

- Oscar Wilde, A Woman of No Importance


 




 Course Home Page          Department Home Page        Loyola Home Page