forked from rick2785/JavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankAccountFacade.java
More file actions
70 lines (40 loc) · 1.51 KB
/
BankAccountFacade.java
File metadata and controls
70 lines (40 loc) · 1.51 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// The Facade Design Pattern decouples or separates the client
// from all of the sub components
// The Facades aim is to simplify interfaces so you don't have
// to worry about what is going on under the hood
public class BankAccountFacade {
private int accountNumber;
private int securityCode;
AccountNumberCheck acctChecker;
SecurityCodeCheck codeChecker;
FundsCheck fundChecker;
WelcomeToBank bankWelcome;
public BankAccountFacade(int newAcctNum, int newSecCode){
accountNumber = newAcctNum;
securityCode = newSecCode;
bankWelcome = new WelcomeToBank();
acctChecker = new AccountNumberCheck();
codeChecker = new SecurityCodeCheck();
fundChecker = new FundsCheck();
}
public int getAccountNumber() { return accountNumber; }
public int getSecurityCode() { return securityCode; }
public void withdrawCash(double cashToGet){
if(acctChecker.accountActive(getAccountNumber()) &&
codeChecker.isCodeCorrect(getSecurityCode()) &&
fundChecker.haveEnoughMoney(cashToGet)) {
System.out.println("Transaction Complete\n");
} else {
System.out.println("Transaction Failed\n");
}
}
public void depositCash(double cashToDeposit){
if(acctChecker.accountActive(getAccountNumber()) &&
codeChecker.isCodeCorrect(getSecurityCode())) {
fundChecker.makeDeposit(cashToDeposit);
System.out.println("Transaction Complete\n");
} else {
System.out.println("Transaction Failed\n");
}
}
}