Question: This is for java. Thank you for your help! Suppose that a class USCurrency has been defined for storing a currency amount in dollars and

 This is for java. Thank you for your help! Suppose thata class USCurrency has been defined for storing a currency amount in

This is for java. Thank you for your help!

Suppose that a class USCurrency has been defined for storing a currency amount in dollars and cents (both integers) where one dollar equals 100 cents. The class includes the following members: Name Description private int totalCents total number of dollars and cents public USCurrency(int dollars, int cents) constructs a currency object with given dollars and cents public int dollars() returns the dollars public int cents() returns the cents public String toString() returns a String in $d.cc notation (-$d.cc for negative amounts) public USCurrency add (USCurrency other) returns the result of adding another currency amount to this one public USCurrency subtract(USCurrency other) returns result of subtracting other currency amount from this one Your task is to modify the class to be comparable by adding an appropriate compareTo method. The currency objects should be compared in the obvious way, with smaller currency amounts considered "less" than larger currency amounts (e.g., -$13.45 { private int totalcents; public USCurrency(int dollars, int cents) { totalcents - dollars * 100 + cents; public int dollars() { return totalcents / 100; public int cents() { return totalCents % 100; public String toString() { int cents - Math.abs(totalCents); String s - cents / 100 + "." + cents % 100 / 10 + cents % 10; if (totalCents

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!