1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
 * This project determines the amount of change
 * in dollars, quarters, dimes, nickels and pennies
 * you will get back with a certain monetary amount.
 *
 * Author: Nick George
 */
 
import java.util.*;
 
class Proj1
{
       public static void main(String[] args) 
       {
              Scanner s = new Scanner(System.in);
              int change, dollars = 0, quarters = 0, dimes = 0, nickels = 0, pennies = 0;
              double paid, bill;
 
              System.out.print("Enter bill amount: $");
              String strBill = s.nextLine();
              bill = Double.parseDouble(strBill);
 
              System.out.print("Enter amount paid: $");
              String strPaid = s.nextLine();
              paid = Double.parseDouble(strPaid);
              
              // Print out change needed
              System.out.println("Change: $" + (paid - bill));
              
              // Get the amount of change we need to return in pennies
              change = (int)((paid - bill) * 100);
              
              // Get the amount of dollars in change, then remove the amount from the change we need to return
              dollars = change / 100;
              System.out.println("       " + dollars + " dollars");
              change -= dollars * 100;
 
              // Get quarters
              quarters = change / 25;
              System.out.println("       " + quarters + " quarters");
              change -= quarters * 25;
 
              // Get dimes
              dimes = change / 10;
              System.out.println("       " + dimes + " dimes");
              change -= dimes * 10;
 
              // Get nickels
              nickels = change / 5;
              System.out.println("       " + nickels + " nickels");
              change -= nickels * 5;
 
              // Penny ammount is whatever is left over
              System.out.println("       " + change + " pennies");
       }
}