/* Program: Coins.java * Author: Dr. Blaise Liffick * Date: Sept. 20, 2007 * Class: CS 161-01 * * This program calculates the number of quarters, dimes, nickels, and pennies * that could be derived from a number of pennies. */ public class Coins { public static void main(String[] args) { int coins = 68; // The amount that needs yet to be converted int quarters, dimes, nickels, pennies; // The number of coins of a given amount. int originalCoins = coins; // The starting number of coins. quarters = coins / 25; // calculates the # of quarters coins %= 25; // figures out what's left after taking out quarters dimes = coins / 10; // calculates the # of dimes coins %= 10; // figures out what's left after taking out dimes nickels = coins / 5; // calculates the # of nickels pennies = coins % 5; // what's left is the number of pennies System.out.println("Making change for " + originalCoins + " cents:"); System.out.println(quarters + " quarter(s)"); System.out.println(dimes + " dime(s)"); System.out.println(nickels + " nickel(s)"); System.out.println(pennies + " penny(s)"); } }