Question: Java. Create a USMoneyDemo class that tests the USMoney class. Your USMoneyDemo should prompt the user twice. The first to enter an integer representing dollars
Java.
Create a USMoneyDemo class that tests the USMoney class. Your USMoneyDemo should prompt the user twice. The first to enter an integer representing dollars and the second to enter an integer representing cents. Use these values to create the first object named x. Do it again for the object named y. Use the code prodvided to create the Usmoneydomo test.
public class Usmoney { int dollars, cents; public Usmoney(int dollars, int cents) { this.dollars = (cents / 100); this.cents = cents % 100; this.dollars += dollars; } public Usmoney() { this(0,0); } public Usmoney(int cents) { dollars = (cents / 100); this.cents = cents % 100; } public int getDollars() { return dollars; } public int getCents() { return cents; } public String toString() { String str; str = "Your Total Amount: " + "$" + dollars + "." + cents +""; return str; } public boolean equals(Object obj) { if (obj instanceof Usmoney) { Usmoney compare = (Usmoney) obj; return this.dollars == compare.getDollars() && this.cents == compare.getCents(); } return false; } public Usmoney plus(Usmoney money) { Usmoney plus = new Usmoney(this.dollars + money.getDollars(), this.cents + money.getCents()); return plus; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
