-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccountController.java
43 lines (39 loc) · 1.18 KB
/
AccountController.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
public class AccountController {
private BankReader reader; // input-view
private BankWriter writer; // output-view
private BankAccount account; // model
/* AccountController 객체 초기
* @param r - input-view 객체
* @param w - output-view 객체
* @param a - model 객체 */
public AccountController(BankReader r, BankWriter w, BankAccount a) {
reader = r;
writer = w;
account = a;
}
/* processTransactions - Q 요청을 할 때까지 고객의 요청을 처리 */
public void processTransactions() {
char command = reader.readCommand("입금 D금액, 출금 W금액, 종료 Q);");
if (command == 'Q') {
writer.showTransaction("서비스를 마칩니다.");
return;
}
else if (command == 'D') {
int amount = reader.readAmount();
if (account.deposit(amount))
writer.showTransaction(amount, "입금");
else
writer.showTransaction("입금 실패");
}
else if (command == 'W') {
int amount = reader.readAmount();
if (account.withdraw(amount))
writer.showTransaction(amount, "출금");
else
writer.showTransaction("출금 실패");
}
else
writer.showTransaction("요청 오류");
this.processTransactions();
}
}