Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions