Question: Need help modifying this JAVA program. Source code is below . Will upvote /** * A Money object models money as dollars and cents **/
Need help modifying this JAVA program. Source code is below . Will upvote


/** * A Money object models money as dollars and cents **/ public class Money{ /* instance attributes */ private int dollars = -1; private byte cents = -1; // Once created we must ensure that 0 = 0 // side effects: object is created with total value of c cents // (adjusting dollars and cents so that 0 = 0 and c >= 0 // side effects: object is created with total value d dollars + c cents // (adjusting this.dollars and this.cents so that 0 100) /** * Returns a String representation of the value of the current object. * * @return The value of the current object is returned as the String"$D.cc" * where D is the number of dollars and cc is the cents of the value. Uses the format() * method from the String class to ensure that the cents are displayed properly (2 spaces * with leading zeros if needed). **/ @Override public String toString(){ return "$" + String.format("%01d", dollars) + "." + String.format("%02d", cents); } }Constructors Modity the Money class that is provided on cuLearn. This is a simple class that stores money as dollars and cents. For example, S12.73 wil be stored as 12 dollars and 73 cents. The cents value stored should never be greater than 99, so 3 dollars and 164 cents should actually be stored as 4 dollars and 64 cents. The provided class has two getter methods that output how many dollars and how many cents a object has at an instant in time. The provided class has also overridden the tostring) which was inherited from the object class. Your first task is to complete the three constructors for the class as follows: public Money) // purpose: create an object with zero dollars and cents. public Money (int c) // purpose: create an object with c cents // precandition: ce // side effects: object is created with total value of c cents 8 (adjusting dollars and cents so that -this.cents <. public money d int c purpose: create an object with dollars and cents preconditions: d-e side effects: is created total value this.dollars this-cents so that this.cents>
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
