forked from rick2785/JavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHasPin.java
More file actions
53 lines (31 loc) · 1.12 KB
/
HasPin.java
File metadata and controls
53 lines (31 loc) · 1.12 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
41
42
43
44
45
46
47
48
49
50
51
52
53
public class HasPin implements ATMState {
ATMMachine atmMachine;
public HasPin(ATMMachine newATMMachine){
atmMachine = newATMMachine;
}
public void insertCard() {
System.out.println("You already entered a card");
}
public void ejectCard() {
System.out.println("Your card is ejected");
atmMachine.setATMState(atmMachine.getNoCardState());
}
public void requestCash(int cashToWithdraw) {
if(cashToWithdraw > atmMachine.cashInMachine){
System.out.println("You don't have that much cash available");
System.out.println("Your card is ejected");
atmMachine.setATMState(atmMachine.getNoCardState());
} else {
System.out.println(cashToWithdraw + " is provided by the machine");
atmMachine.setCashInMachine(atmMachine.cashInMachine - cashToWithdraw);
System.out.println("Your card is ejected");
atmMachine.setATMState(atmMachine.getNoCardState());
if(atmMachine.cashInMachine <= 0){
atmMachine.setATMState(atmMachine.getNoCashState());
}
}
}
public void insertPin(int pinEntered) {
System.out.println("You already entered a PIN");
}
}