!”
Β
- Create a new class called Money, and include:
Instance variables for dollars (int) and cents (int).
A no-argument constructor which sets dollars and cents to zero.
A two-argument constructor accepting integer dollars and cents.
Get methods for dollars and cents.
A toString method which would print 6 dollars and 5 cents as:
$ 6.05
(hint: to get the leading zero, you can take a substring of the last two characters of
“0”+the String values of cents.)
compareTo and equals methods.
- Write a small test program including statements like the following and others to test the methods in the class Money.
Money m1 = new Money();
Money m2 = new Money(6,5)
System.out.println(m1.getCents());
System.out.println(m2.getDollars());
System.out.println(m2);
System.out.println(m1.compareTo(m2));Β System.out.println(m1.equals(m2));





