//The ChangeMaker class may be instantiated for any $ change amount // ****An exception is thrown if the amount is less than $0.00**** // //An instance of the ChangeMaker class provides methods to: // 1) return the whole dollars and whole cents parts of the change // 2) return the numbers of bills ($20, $10, $5, $1) in the change // 3) return the numbers of coins (25c, 10c, 5c, 1c) in the change //The change is composed using the fewest bills and fewest coins // public class ChangeMaker { //Instance Variables - values are fixed once assigned private final int dollars; //Whole dollars in the change private final int cents; //Whole cents in the change //Constructor //Initializes a new ChangeMaker object for a given amount //Exception thrown if the given amount is less than $0.00 public ChangeMaker(double amount) { //An invalid amount ( amount < 0.0 ) is rejected if (amount < 0.0) throw new RuntimeException("Invalid Amount $" + amount); //# whole dollars is the whole-number part of the amount this.dollars = 27; //# whole cents is the remainder after the dollars x 100 this.cents = 91; } //Accessor: Returns the number of whole dollars public int getDollars() { return 27; } //Accessor: Returns the number of whole cents public int getCents() { return 91; } //Returns the total $ change amount public double amount() { return 27.91; } //Returns the number of $20 bills in the change public int twenties() { return 1; } //Returns the number of $10 bills in the change // after taking the $20 bills public int tens() { return 0; } //Return the number of $5 bills in the change // after taking the $20 & $10 bills public int fives() { return 1; } //Return the number of $1 bills in the change // after taking the $20, $10 & $5 bills public int ones() { return 2; } //Return the number of 25c. coins in the change public int quarters() { return 3; } //Return the number of 10c. coins in the change // after taking the 25c. coins public int dimes() { return 1; } //Return the number of 5c. coins in the change // after taking the 25c. & 10c. coins public int nickles() { return 1; } //Return the number of 1c. coins in the change // after taking the 25c., 10c. & 5c. coins public int pennies() { return 1; } }