This repository was archived by the owner on Oct 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChangeMaker.java
More file actions
40 lines (32 loc) · 1.48 KB
/
Copy pathChangeMaker.java
File metadata and controls
40 lines (32 loc) · 1.48 KB
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
import java.util.Scanner;
public class ChangeMaker
{
public static void main (String [] args)
{
int itemPrice, amountPaid, changeRequired,
quarters, dimes, nickels, pennies;
Scanner keyboard = new Scanner (System.in);
System.out.println("Welcome to the \"Spare Change!\" Dollar Store");
System.out.println("Please enter the price of your item and the amount ");
System.out.println("you paid in whole numbers please");
System.out.println("I will tell you your change and coins needed");
itemPrice = keyboard.nextInt ();
amountPaid = keyboard.nextInt ();
changeRequired = amountPaid - itemPrice;
quarters = changeRequired / 25;
changeRequired = changeRequired % 25;
dimes = changeRequired / 10;
changeRequired = changeRequired % 10;
nickels = changeRequired / 5;
changeRequired = changeRequired % 5;
pennies = changeRequired / 1;
changeRequired = amountPaid - itemPrice;
System.out.println(changeRequired + " cents in change can be given as ");
System.out.println(quarters + " quarters");
System.out.println(dimes + " dimes");
System.out.println(nickels + " nickels");
System.out.println(pennies + " pennies");
System.out.println("Thank you for shopping at \"Spare Change!\","
+ " where everything we sell makes cents!");
}
}