// package chapter9; /** * Title: Chapter 9, "Object-Oriented Software Development" * Description: Examples for Chapter 9 * Copyright: Copyright (c) 2000 * Company: Armstrong Atlantic State University * @author Y. Daniel Liang * @version 1.0 */ // TestRationalClass.java: Demonstrate using the Rational class public class TestRationalClass { /**Main method*/ public static void main(String[] args) { // Create and initialize two rational numbers r1 and r2. Rational r1 = new Rational(4,2); Rational r2 = new Rational(2,3); // Display results System.out.println(r1.toString() + " + " + r2.toString() + " = " + (r1.add(r2)).toString()); System.out.println(r1.toString() + " - " + r2.toString() + " = " + (r1.subtract(r2)).toString()); System.out.println(r1.toString() + " * " + r2.toString() + " = " + (r1.multiply(r2)).toString()); System.out.println(r1.toString() + " / " + r2.toString() + " = " + (r1.divide(r2)).toString()); } }