I have all but one line from the main class completed, I am just running into a dead end when working on the "plus" method.
"Create a USMoney class with two integer instance variables named dollars and cents. The class should have two accessor methods called getDollars and getCents. The class should have a constructor with two parameters for initializing a USMoney object. The constructor should check that the cents value is between 0 and 99 and, if not, transfer some of the cents to the dollars variable to make it between 0 and 99. (Note: You need not worry, though, for the purposes of this assignment, about reacting to and handling negative inputs to either of the two variables.)
Include in your class a method called plus that takes a USMoney object as an input parameter. This function should create and return a new USMoney object representing the sum of the calling object and the parameter. It does not modify the values of the two existing objects. Like the constructor, this method should ensure that the value of the cents instance variable of the returned object is between 0 and 99. Provide Javadoc-style documentation (comments) for the 3 methods and the constructor of your USMoney class.
When you are finished, you should be able to run the following main class:
with expected output as follows:
Account 2 data: 541 dollars and 43 cents
Account 1 data: 13 dollars and 57 cents
Account 3 data (sum): 555 dollars and 0 cents"
Do your coding bit by bit. Do one tiny step, then compile and run the code, then go on to the next step. Get yourself your Money class, and give it a toString() method which returns something like "$123.45". Then you can test it like this:-And add more methods and try them out similarly.
Note the behaviour your assignment describes is that of an immutable class. That never allows the dollar and cent fields to be changed after they have been initialised. So adding creates a new Money object, rather like here.
Blood pressure normal? What do I change to get "magnificent"? Maybe this tiny ad?