// a small program to make change, based on an enum called Coin // changing Coin can make this program behave in different ways import java.util.Scanner; class MakeChange { public static void main(String[] args) { // make an array of the coins Coin[] coins = Coin.values(); // Scanner to listen to keyboard Scanner scanner = new Scanner(System.in); // what is the basic unit called? String unitName = Coin.getUnitName(); // infinite loop! while (true) { // get input from user, quit on 0 System.out.print("Enter number of " +unitName + ", or 0 to quit: "); int units = scanner.nextInt(); if (units <= 0) break; // start the report System.out.println(units + " " +unitName+ " consists of:"); // go through each of the coins in reverse order for (int i=coins.length-1; i>=0; i--) { // calculate how many coins there are of this value, remove them from units int value = coins[i].getValue(); int numCoins = units / value; units -= (numCoins * value); // print System.out.println("\t" + coins[i] +" coins: " +numCoins); } } // outta here! System.out.println("Good bye!"); } }