package rebelsky.fractions; import java.io.PrintWriter; import java.io.InputStreamReader; import java.io.BufferedReader; /** * A simple calculator. Reads in two fractions and prints their * sum and product. * * @author Samuel A. Rebelsky * @version 1.0 of September 2005 */ public class Calculator { // +------+-------------------------------------------------------------- // | Main | // +------+ public static void main(String[] args) throws Exception { // Prepare for input and output PrintWriter pen = new PrintWriter(System.out, true); BufferedReader eyes = new BufferedReader(new InputStreamReader(System.in)); // Read the two fractions. pen.print("Please enter a fraction of the form 'num/denom': "); pen.flush(); Fraction f1 = new Fraction(eyes.readLine()); pen.print("Please enter another fraction of the form 'num/denom': "); pen.flush(); Fraction f2 = new Fraction(eyes.readLine()); // Print the results pen.println(f1 + " + " + f2 + " = " + f1.add(f2)); pen.println(f1 + " * " + f2 + " = " + f1.multiply(f2)); } // main(String[]) } // class Calculator