# // David Willmore

Period 7

ÏÕÖ×public class FractionTester ÏÏ§{ ÏÏ§ÏÞßàpublic static void main ( String [] args) ÏÏ§ÏÏ§{ ÏÏ§ÏÏ¨¹íÏFraction Half = new Fraction ( 1 , 2 ); ÏÏ§ÏÏ¨¹íÏFraction Third = new Fraction (1, 3 ); ÏÏ§ÏÏ¨¹íÏFraction ans = new Fraction ( 6 , 4); ÏÏ§ÏÏ§ ÏÏ§ÏÏ¨¹¹ÏSystem.out.println ( " David Willmore Period 7\n " ); ÏÏ§ÏÏ¨¹¹ÏSystem.out.println ( Half + " + " + Third + " = " + Half.add(Third)) ; ÏÏ§ÏÏ¨¹¹ÏSystem.out.println ( Half + " - " + Third + " = " + Half.substract(Third)) ; ÏÏ§ÏÏ¨¹¹ÏSystem.out.println ( Half + " * " + Third + " = " + Half.multiply(Third)) ; ÏÏ§ÏÏ¨¹¹ÏSystem.out.println ( Half + " / " + Third + " = " + Half.divide(Third)) ; ÏÏ§ÏÏ¨¹¹ÏSystem.out.println ( Half.compareTo(Third)) ; ÏÏ§ÏÏ©} ÏÏ©}

// David Willmore

Period 7

public class Fraction implements Comparable<Fraction> { private int myN; private int myD; public Fraction ( int n , int d ) { myN = n; myD = d; } public Fraction ( int n) { myN = n; myD = 1; } public String toString() { String ans += ans += ans += return ans = ""; myN; "/"; myD; ans;

} public int getN() { return myN; } public int getD() { return myD; } public Fraction add(Fraction other) { int n1 = (myN * other.getD() + other.getN() * myD); int n2 = (other.getD() * myD); Fraction ans = new Fraction (n1 , n2 ); return ans; } public Fraction substract(Fraction other) { int n1 = ((myN * other.getD() - other.getN() * myD)); int n2 = (( other.getD() * myD)); Fraction ans = new Fraction( n1 ,n2 ); return ans; } public Fraction multiply(Fraction other) { int n1 = (this.getN() * other.getN()); int n2 = (this.getD() * other.getD()); Fraction ans = new Fraction ( n1,n2 ); return ans; } public Fraction divide(Fraction other)

{ Fraction rec = new Fraction ( other.getD() , other.getN() ) ; Fraction ans = this.multiply( rec ); return ans; } public Fraction simplify() { for ( int i = 1; i <= myD ; i++ ) if ( myN % i == 0 && myD % i == 0 ) { myN /= i; myD /= i; } Fraction ans = new Fraction ( myN , myD); return ans; } public int compareTo(Fraction other) { int ans = 0; double x = (double)myN/myD; double j = (double)other.getN()/other.getD(); if(x<j) ans = -1; if(x>j) ans = 1; return ans; } }