Source of ChangeMaker.java


  1: //ChangeMaker.java
  2: //Computes required number of quarters, nickels, dimes and pennies
  3: //to make any amount from 1 to 99 cents.
  4: 
  5: import java.util.Scanner;
  6: 
  7: public class ChangeMaker
  8: {
  9:     public static void main(String[] args)
 10:     {
 11:         int amount, originalAmount,
 12:             quarters, dimes, nickels, pennies;
 13: 
 14:         System.out.println("Enter a whole number from 1 to 99.");
 15:         System.out.println("I will find a combination of coins");
 16:         System.out.println("that equals that amount of change.");
 17: 
 18:         Scanner keyboard = new Scanner(System.in);
 19:         amount = keyboard.nextInt();
 20: 
 21:         originalAmount = amount;
 22:         quarters = amount / 25;
 23:         amount = amount % 25;
 24:         dimes = amount / 10;
 25:         amount = amount % 10;
 26:         nickels = amount / 5;
 27:         amount = amount % 5;
 28:         pennies = amount;
 29: 
 30:         System.out.println(originalAmount +
 31:                            " cents in coins can be given as:");
 32:         System.out.println(quarters + " quarters");
 33:         System.out.println(dimes + " dimes");
 34:         System.out.println(nickels + " nickels and");
 35:         System.out.println(pennies + " pennies");
 36:     }
 37: }