Question: QUESTION 1 Modify the Money class that is provided. This is a simple class that stores money as dollars and cents. For example, $12.73 will
QUESTION 1 Modify the Money class that is provided. This is a simple class that stores money as dollars and cents. For example, $12.73 will 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 be stored as 4 dollars and 64 cents. The class has only one method, toString(. which returns a String representation of the money object. Your first task is to create four constructors for the class as follows: public Money((...) // creates a Money object with zero money public Money(int dollars, int cents) {...} // creates a Money object with total value as specified by // the input values. Input values are assumed to satisfy Il dollars > @ and cents > 0. public Money(int cents)(...) // creates a Money object with value as specified by // the input cents. Input value is assumed to satisfy // cents > @ pubic Money (int[] coins)(...) 1/ creates a Money object with value as specified by the input array. // The array will have six (6) elements, corresponding to the coins 11 toonies, loonies, quarters, dimes, nickels, pennies 1/ ($2, $1, $e.25, 50.10, $e.es, 50.01) In all the constructors, be sure that the internal state (dollars and cents) represents the total money and that cents is not greater than 99. The Money class has a toString method to help test/debug your code. It returns a String representation of the money. Use the testing program TestMoney.java to help test your constructors. Nest, add the following instance methods to your Money class: public void add(int c){...} // adds c cents to the current value // Again, be sure the internal states does not have cents greater than 99 public void add(int d, int c){...} // adds d dollars and c cents to the current value 1/ Again, be sure the internal states does not have cents greater than 99 public int remove(int c)...) V/ removes >= @ cents from current value if current I value is large enough. Otherwise, removes as much as it can. // Returns the actual amount of cents removed (may be > 180), 17 and adjusts the internal state
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
