package Chap3;
import java.io.*;

// CSC108 Chapter 3, Question 17
// Name:  Iam Me         Student ID: 555555555
// Tutor: Andria Hunter  Prof: Ken Jackson
//
// Program Description: Reads an integer value (some dollar
//     amount between 0 and 100), and prints out the amount of
//     change that would be received from one dollar.  The amount
//     is expressed in quarters, dimes, nickels, and pennies.

class q17 {

   // Main method to read the integer purchase amount, and to
   // determine and print the change.

   public static void main (String[] args) throws IOException {

      // Declare stdin so data can be read from input.
      DataInputStream stdin = new DataInputStream (System.in);

      final int DOLLAR = 100;  // One dollar in cents
      final int QUARTER = 25;  // One quarter in cents
      final int DIME = 10;     // One dime in cents
      final int NICKEL = 5;    // One nickel in cents

      int value;               // Integer value read from input

      // Read dollar amount from stdin.
      System.out.println ("Enter the purchase amount [0-100]: ");
      value = Integer.parseInt(stdin.readLine());

      // Report error if invalid integer is entered.
      if (value<0 || value>DOLLAR) {
         System.out.println ("Invalid purchase amount. Must be between 0 and 100.");
      }

      // Subtract the purchase amount from 1 dollar, and determine
      // the number of quarters, dimes, nickels, and pennies that
      // this change amount can be divided into.

      else {
         // Amount of change that would be received from one dollar
         int change = DOLLAR - value;

         int num_quarter=0;       // Counts number of quarters
         int num_dime=0;          // Counts number of dimes
         int num_nickel=0;        // Counts number of nickels
         int num_penny=0;         // Counts number of pennies

         // Use integer division to determine how many quarters, and
         // then use mod operation to determine the remaining change.
         // Repeat for dimes, nickels, and pennies.

         num_quarter = change / QUARTER;
         change = change % QUARTER;

         num_dime = change / DIME;
         change = change % DIME;

         num_nickel = change / NICKEL;
         change = change % NICKEL;

         num_penny = change;

         // Report change to standard out.

         System.out.println ("Your change of "+(DOLLAR-value)+" cents is given as:");
         System.out.println (" "+num_quarter+" Quarters");
         System.out.println (" "+num_dime+" Dimes");
         System.out.println (" "+num_nickel+" Nickels");
         System.out.println (" "+num_penny+" Pennies");
      }
   }
}

