package rational; public class RationalNumberSkeleton { private int numerator; private int denominator; public RationalNumberSkeleton(int numer, int denom) { numerator = numer; denominator = denom; if (denominator == 0) // handle 0 denominator denominator = 1; if (denominator < 0) { // Make the numerator "store" the sign numerator = numerator * -1; denominator = denominator * -1; } reduce(); } public double getDecimalEquivalent() { return 0; } public int getNumerator() { return numerator; } public int getDenominator() { return denominator; } public RationalNumber reciprocal() { return null; } public RationalNumber add(RationalNumber op2) { return null; } public RationalNumber subtract(RationalNumber op2) { return null; } public RationalNumber multiply(RationalNumber op2) { return null; } public RationalNumber divide(RationalNumber op2) { return null; } public boolean equals(RationalNumber op2) { return false; } public String toString() { if (numerator == 0) return "0"; else if (denominator == 1) return numerator + ""; else return numerator + "/" + denominator; } // This assumes that the numerator is not negative private void reduce() { // divide numerator and denominator by gcd to reduce if (numerator != 0) { int common = gcd(Math.abs(numerator), denominator); numerator = numerator / common; denominator = denominator / common; } else denominator = 1; // so 0 is unique } private int gcd(int num1, int num2) { // a slow, non-traditional method while (num1 != num2) if (num1 > num2) num1 = num1 - num2; else num2 = num2 - num1; return num1; } }