Lab 08 Math 03
Lab 08 Math 03
Assignment Purpose:
The purpose of this lab is to demonstrate knowledge of creating a class with object
methods, instantiate multiple objects of the created class, and then call the object
methods from the main program method. Additionally, this lab requires knowledge of
the GUI input output and string to number conversion.
This lab assignment continues the Rational class that was started with the Lab08MATH02
assignment. Now comes the times to add, subtract, multiply and divide fractions with your nifty
Rational class. This assignment will also be the first unit lab assignment. A unit assignment implies
a more challenging assignment that carries greater weight for your average computation. A unit
assignment involves bringing together a greater number of computer skills in one assignment. For
instance, the last keyword assignment provided complete main methods, which handled all the GUI
input and output. For this assignment you will need to write the Rational class and also handle most
of the code in the main method.
import javax.swing.JOptionPane;
r3.multiply(r1,r2);
String mul = r1.getOriginal() + " * " + r2.getOriginal() + " = " + r3.getRational();
r3.divide(r1,r2);
String div = r1.getOriginal() + " / " + r2.getOriginal() + " = " + r3.getRational();
r3.add(r1,r2);
String add = r1.getOriginal() + " + " + r2.getOriginal() + " = " + r3.getRational();
r3.subtract(r1,r2);
String sub = r1.getOriginal() + " - " + r2.getOriginal() + " = " + r3.getRational();
JOptionPane.showMessageDialog(null,output);
System.exit(0);
}
Exposure Java 2009, APCS Edition Lab08MATH03 Page 1 06-10-09
}
class Rational
{
public Rational() { }
Note that in the GUI output window above, 4 lines of output are shown. In the 80 and 90 point
versions, only the first 2 lines are significant. The sum and difference will appear to be the same as
the quotient.
NOTE: As with the 80 point version, only the first 2 lines of output are significant.