[SOLVED] CS212 Lab 14 and 15-Class Called Money

25.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon Lab14Lab15-Money-Class-owut1h.zip (51.1 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
πŸ”’ Securely Powered by:
Secure Checkout
Rate this product

!”

Β 

  1. 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.

 

  1. 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));

 

 

 

 

  • Lab14Lab15-Money-Class-owut1h.zip