-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChangeMaker1.java
61 lines (49 loc) · 1.24 KB
/
ChangeMaker1.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
59
60
61
import java.util.Scanner;
public class ChangeMaker1 {
static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
makeChange();
}
//Modifier: public static
//Return Type : void
//Method Name: makeChange
//Args: -
public static void makeChange() {
//ask user for input
System.out.println("Enter change needed");
int amount = scanner.nextInt();
//define variables
int remainder = 0;
int quarters = 0;
int dimes = 0;
int nickels = 0;
//max change 99 cents
if (amount <= 1 && amount >= 99) {
System.out.println("Does not compute");
}
//breaking down user input into change
quarters = amount / 25;
remainder = amount % 25;
dimes = remainder / 10;
remainder = remainder % 10;
nickels = remainder / 5;
remainder = remainder % 5;
//do not print any change that is 0
while (quarters != 0) {
System.out.println(quarters + " quarters");
break;
}
while (dimes != 0) {
System.out.println(dimes + " dimes");
break;
}
while (nickels != 0) {
System.out.println(nickels + " nickels");
break;
}
while (remainder != 0) {
System.out.println(remainder + " pennies");
break;
}
}
}