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

$25

File Name: CS212_Lab_14_and_15_Class_Called_Money___.zip
File Size: 386.22 KB

SKU: [Solved] CS212 Lab 14 and 15-Class Called Money Category: Tag:
5/5 - (1 vote)

!

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

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CS212 Lab 14 and 15-Class Called Money[Solved] CS212 Lab 14 and 15-Class Called Money
$25