/***************************************************************** * Lab 1: Vending Machine Change * Programmer: Put your name here * * Class: COMP 110-001 Instructor: Yi Hong * * Pledge: I have neither given nor received unauthorized aid * on this program. * * Description: This program outputs the change for a vending machine. * * Input: a whole number from 1 to 99 * * Output: a combination of coins that equals that amount of change. * ******************************************************************/ import java.util.Scanner; public class VendingMachine { public static void main(String[] args) { int amount, originalAmount, quarters, dimes, nickels, pennies; System.out.println("Enter a whole number from 1 to 99."); System.out.println("I will output a combination of coins"); System.out.println("that equals that amount of change."); Scanner keyboard = new Scanner(System.in); //read the amount in the variable amount amount = keyboard.nextInt(); originalAmount = amount; quarters = amount / 25; amount = amount % 25; dimes = amount / 10; amount = amount % 10; nickels = amount / 5; amount = amount % 5; pennies = amount; System.out.println(originalAmount + " cents in coins can be given as:"); System.out.println(quarters + " quarters"); System.out.println(dimes + " dimes"); System.out.println(nickels + " nickels and"); System.out.println(pennies + " pennies"); keyboard.close(); } }