brainfrz

Untitled

Feb 10th, 2016
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.34 KB | None | 0 0
  1. /**************************************************************************************************
  2.  * Program Name   : Week 3 - Rational Number
  3.  * Author         : Terry Weiss
  4.  * Date           : February 10, 2016
  5.  * Course/Section : CSC112 - 801
  6.  * Program Description: This program has a RationalNumber class that defines a fraction. It has
  7.  *     two data members for the numerator and denominator, passed by the constructor, and two
  8.  *     methods that display the number as a fraction and a decimal.
  9.  * This program also has a Relatable interface, which has three methods to compare "equals",
  10.  *     "isGreater" and "isLess", and is implemented by RationalNumber.
  11.  **************************************************************************************************/
  12.  
  13. public class RelatableTest {
  14.     public static void main(String[] args) {
  15.         final int NUMERATOR1 = 5,  DENOMINATOR1 = 8; //First fraction should be smaller
  16.         final int NUMERATOR2 = 10, DENOMINATOR2 = 4; //Second fraction should be bigger
  17.  
  18.         System.out.println("Creating Fraction 1:");
  19.         RationalNumber fraction1 = new RationalNumber(NUMERATOR1, DENOMINATOR1);
  20.         System.out.println(fraction1);
  21.  
  22.         System.out.println("Creating Fraction 2:");
  23.         RationalNumber fraction2 = new RationalNumber(NUMERATOR2, DENOMINATOR2);
  24.         System.out.println(fraction1);
  25.  
  26.         System.out.println();
  27.  
  28.         System.out.println("Fraction 1 < Fraction 2 should be true");
  29.         System.out.println(fraction1.isLess(fraction2));
  30.  
  31.         System.out.println();
  32.  
  33.         System.out.println("Fraction 2 < Fraction 1 should be false");
  34.         System.out.println(fraction2.isLess(fraction1));
  35.  
  36.         System.out.println();
  37.  
  38.         System.out.println("Fraction 1 > Fraction 2 should be false");
  39.         System.out.println(fraction1.isGreater(fraction2));
  40.  
  41.         System.out.println();
  42.  
  43.         System.out.println("Fraction 2 > Fraction 1 should be true");
  44.         System.out.println(fraction2.isGreater(fraction1));
  45.  
  46.         System.out.println();
  47.  
  48.         System.out.println("Fraction 1 == Fraction 1 should be true");
  49.         System.out.println(fraction1.equals(fraction1));
  50.  
  51.         System.out.println();
  52.  
  53.         System.out.println("Fraction 1 == Fraction 2 should be false");
  54.         System.out.println(fraction1.equals(fraction2));
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment