COMP 170    -    PROGRAM VIII  (Fraction Calculator)

Due:  Monday, 29 March 1999

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).  A static method to find the greatest common divisor of two non-negative integers should also reside inside the Fraction class.  (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:
2
3
Thank you.  The sum of 13/2 and 2/3 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:

All of the following should be contained in a two-pocket folder with your name, "Comp 170", and "day"/"evening" designation  in large letters on the outside of the folder.

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