-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdollars.java
41 lines (33 loc) · 1.37 KB
/
dollars.java
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
import java.util.Scanner;
public class dollars
{
/* Program that prompts for and reads a double value representing a monetary value.
Then determine the fewest number of each bill and coin needed to represent that amount,
starting with the highest (assume ten dollar bill is the maximum needed)
quarter = 0.25
dime = 0.10
nickel = 0.05
penny = 0.01
*/
public static void main(String[] args)
{
double ten_dollar = 10.00;
double five_dollar = 5.00;
double one_dollar = 1.00;
double quarter = 0.25;
double dime = 0.10;
double nickel = 0.05;
double penny = 0.01;
double myCoinJar;
Scanner myJar = new Scanner(System.in);
System.out.println("Enter dollar amount $");
myCoinJar = myJar.nextDouble();
System.out.println( (int)(myCoinJar/ten_dollar) + "Ten Dollar Bills");
System.out.println( (int)(myCoinJar/five_dollar) + "Five Dollar Bills");
System.out.println( (int)(myCoinJar/one_dollar) + "One Dollar Bills");
System.out.println( (int)(quarter * myCoinJar) + "Quarters");
System.out.println( (int)(dime * myCoinJar) + "Dimes");
System.out.println( (int)(nickel * myCoinJar) + "Nickels");
System.out.println( (int)(penny * myCoinJar) + "Pennies");
}
}