/**************************************************************************************************
* Program Name : Week 3 - Rational Number
* Author : Terry Weiss
* Date : February 10, 2016
* Course/Section : CSC112 - 801
* Program Description: This program has a RationalNumber class that defines a fraction. It has
* two data members for the numerator and denominator, passed by the constructor, and two
* methods that display the number as a fraction and a decimal.
* This program also has a Relatable interface, which has three methods to compare "equals",
* "isGreater" and "isLess", and is implemented by RationalNumber.
**************************************************************************************************/
public class RelatableTest {
public static void main(String[] args) {
final int NUMERATOR1 = 5, DENOMINATOR1 = 8; //First fraction should be smaller
final int NUMERATOR2 = 10, DENOMINATOR2 = 4; //Second fraction should be bigger
System.out.println("Creating Fraction 1:");
RationalNumber fraction1 = new RationalNumber(NUMERATOR1, DENOMINATOR1);
System.out.println(fraction1);
System.out.println("Creating Fraction 2:");
RationalNumber fraction2 = new RationalNumber(NUMERATOR2, DENOMINATOR2);
System.out.println(fraction1);
System.out.println();
System.out.println("Fraction 1 < Fraction 2 should be true");
System.out.println(fraction1.isLess(fraction2));
System.out.println();
System.out.println("Fraction 2 < Fraction 1 should be false");
System.out.println(fraction2.isLess(fraction1));
System.out.println();
System.out.println("Fraction 1 > Fraction 2 should be false");
System.out.println(fraction1.isGreater(fraction2));
System.out.println();
System.out.println("Fraction 2 > Fraction 1 should be true");
System.out.println(fraction2.isGreater(fraction1));
System.out.println();
System.out.println("Fraction 1 == Fraction 1 should be true");
System.out.println(fraction1.equals(fraction1));
System.out.println();
System.out.println("Fraction 1 == Fraction 2 should be false");
System.out.println(fraction1.equals(fraction2));
}
}
Comments