-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExercise03_07.java
58 lines (48 loc) · 1.82 KB
/
Exercise03_07.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package Chapter3;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.util.Scanner;
/**
*
* @author jorda
*/
public class Exercise03_07 {
public static void main(String[] args) {
// Create a Scanner
Scanner input = new Scanner(System.in);
// Receive the amount
System.out.print(
"Enter an amount in double, for example 11.56: ");
double amount = input.nextDouble();
int remainingAmount = (int)(amount * 100);
// Find the number of one dollars
int numberOfOneDollars = remainingAmount / 100;
remainingAmount = remainingAmount % 100;
// Find the number of quarters in the remaining amount
int numberOfQuarters = remainingAmount / 25;
remainingAmount = remainingAmount % 25;
// Find the number of dimes in the remaining amount
int numberOfDimes = remainingAmount / 10;
remainingAmount = remainingAmount % 10;
// Find the number of nickels in the remaining amount
int numberOfNickels = remainingAmount / 5;
remainingAmount = remainingAmount % 5;
// Find the number of pennies in the remaining amount
int numberOfPennies = remainingAmount;
// Display results
System.out.println("Your amount " + amount + " consists of");
if (numberOfOneDollars > 0)
System.out.println(numberOfOneDollars + " " + " dollars");
if (numberOfQuarters > 0)
System.out.println(numberOfQuarters + " " + " quarters ");
if (numberOfDimes > 0)
System.out.println(numberOfDimes + " " + " dimes");
if (numberOfNickels > 0)
System.out.println(numberOfNickels + " " + " nickel");
if (numberOfPennies > 0)
System.out.println(numberOfPennies + " " + " penny");
}
}