The Classes Homework

Purpose:  The purpose of this homework is to gain experience working with classes.

Goal:  Write me three classes

The Money class should implement three digit decimals.  You are required to implement it using three integers.  Those integers are the ones place, the tenths place, and the hundredths place of the quantity to be stored.  None of these ints should leave the range 0 ... 10

The fraction class should be implemented using two integers, and you can steal the one from my web site for a place to start.  The value should be represented as top/bottom, where top and bottom are the integers.

The FixedDecimal class should represent numbers using a single integer.  The value to be held should be multiplied by 1000 and then rounded.  This number is stored in the integer. See the table below for examples.
Value Int to Store
1 1000
0 0
1.4567 1458
.031 31
12.3 12300

They should have the functions listed below
 
public class Money {
    private int dollars, dimes, pennies;
    public Money(float f) { // A contructor that takes a float
    }
    public float toFloat() { // returns a floating point number 
    }
    public String toString() { // returns a string
    }
    public Money add(Money operand) { // returns the sum of this money plus 
    }                                 // operand.  Does NOT change this!
}
public class Fraction {
    private int top, bottom;
    public Fraction(int top, int bottom) { // A constructor taking two ints
    }
    public Fraction(float f) { // A constructor taking a float
    }
    public float toFloat() { // returns a floating point number describing the float
    }
    public String toString() { // returns a string
    }
    public Fraction add(Fraction other) { // Same as money.add
    }
}

public class FixedDecimal {
    private int theNum;
    public FixedDecimal(float f) { // A constructor taking a float
    }
    public float toFloat() { // returns a floating point number describing the float
    }
    public String toString() { // returns a string
    }
    public FixedDecimal add(FixedDecimal other) { // Same as money.add
    }
}

When you're done your classes should be able to run with my main which is listed below
 
public class Tester {
   public static void main(String args[]) {
      Fraction f1 = new Fraction(10, 3);
      System.out.println("Should print 10 / 3:" + f1);
      Fraction f2 = new Fraction(1,5);
      Fraction f3 = f2.add(f1);
      System.out.println("Should be 10/3 + 1/5 (about 53/15): " + f3);
      Fraction f4 = new Fraction(0.1);
      System.out.println("Should be equal to 1/10: " +f4);
      System.out.print("Should be about 3.33333: ");
      System.out.println(f1.toFloat());

      Money m1 = new Money(1.23);
      System.out.println("Should print $1.23: " + m1);
      Money m2 = new Money(5.11);
      Money m3 = m2.add(m1);
      System.out.println("Should be 5.11 + 1.23 (6.34: " + m3);
      Money m4 = new Money(5.00);
      System.out.println("This might give an error");
      Money m5 = m4.add(m3);
      System.out.println("What is 6.34 + 5.00? " +m5);
      System.out.print("Should be about 6.34: ");
      System.out.println(m3.toFloat());
      System.out.println("I should get an error message on the next line");
      Money m6 = new Money(11.99);

      FixedDecimal d1 = new FixedDecimal(1.76);
      System.out.println("Should be 1.76: " + d1);
      FixedDecimal d2 = new FixedDecimal(987.65439);
      System.out.println("Should be 987.6544 (remember it should round)"+d2);
      FixedDecimal d3 = new FixedDecimal(10000.0);
      System.out.println("That should not have given an error. The number is " +d3);
      FixedDecimal d4 = d1.add(d1);
      System.out.println("Should give 3.52: " + d4);
      System.out.print("Testing tofloat.  Should be 1.76: ");
      System.out.println(d1.toFloat());
   }
}

Scoring:
One point for every correct line of output. (15 possible ... I'm counting the println's)
Two points if you get subtract working for money.
One point total if you get subtract working for both FixedDecimal and Fractions.
Four points if you make a SciNotation class with all the functions the Money or FixedDecimal classes have.
Twelve points for a fairing to fit a '91 Honda Nighthawk.

Hints:

There might be bugs in the code above.  I've not tested it, so feel free to fix anything needed.

Handle the error cases for dollars (like dollars over $9.99) with an error message.  Feel free to set the amount to anything you want, as long as it's between 0.00 and 9.99

Answers are OK if they have to correct NUMERIC value.  If I wanted 1/3 and you say 10/30, that's fine.

Answers in scientific notation are O.K.

Feel free to send me email.  Feel free to visit Professor Peterson or send him email.