Question: I need to write the toString method. Other methods not included are add() and subtract(). As well as getter for dollars and cents * Provides
* Provides a string representation of the current Money object, in * the form Smm.mm. Negative values have a minus sign before the dollar * sign. Zero dollar amounts are represented with one zero between the * dollar sign and the decimal point. Cents that are multiples of 10 * still show two decimal places. (Examples: $12.34,$6.50, $0.99 $0.99, $0.00) *@return the string representation @Override public String tostring) f //TODO complete this method return null: //replace this return statement public class Money i 10 //fields private long dollars: private byte cents: 12 13 51 6 * Default constructor. Creates a new Money * Sets both dollars and cents to zero. object public Money ) dollars0: cents = 0; 41 /** Full constructor. Creates a new Money object. Dollars and c are normalized. IE one is negative and the other is + positive, the resulting obiect will be the natural addi tion or the values. (Example: 2 dollazs and -5 cents is converted to 1 dollar and 95 cents.) II the absolute value of cents is greater than 99, * the resulting object will canny the extra cents * (Example: 1 dollar and 105 cents is converted to * A negative value is represented with both the dollars and cents nege into the dollars eparam dollars the number of dollars in the amount * eparam cents the number of cents in the amount public Money (long dollars, byte cents) { long value dollars 10o: value += cents; this.dollars value 100: this. cents = (byte) (value % 100)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
