-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBankATM.java
More file actions
100 lines (90 loc) · 2.58 KB
/
Copy pathBankATM.java
File metadata and controls
100 lines (90 loc) · 2.58 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package com.mystudy.am03_scanner_bank;
import java.util.Scanner;
//[실습] 은행의 ATM
//1.입금 2.출금 3.통장확인 0.종료
//------------------------------
//계좌를 하나 만들고 입금/출금/통장확인 작업을 처리
public class BankATM {
private int money; //통장계좌
private Scanner sc = new Scanner(System.in);
// public static void main(String[] args) {
//
// BankATM atm = new BankATM();
// atm.startBank();
// }
public void startBank() {
System.out.println(">> 어서오세요");
while (true) {
if (bankATM() == false) {
break;
};
}
System.out.println(">>작업을 종료했습니다.");
}
private boolean bankATM() {
boolean jobContinue = true;
showMenu();
int select = 99;
try {
select = Integer.parseInt(sc.nextLine());
} catch (NumberFormatException e) {
System.out.println("잘못된 값이 입력되었습니다."
+ " 메뉴(0~3) 숫자만 선택하세요");
return jobContinue;
}
if (select == 1) {
//System.out.println("입금작업처리~~");
inputMoney();
} else if (select == 2) {
//System.out.println("출금작업처리~~");
outputMoney();
} else if (select == 3) {
//System.out.println("통장확인 작업처리~~");
showMoney();
} else if (select == 0) {
System.out.println("종료작업처리~~");
jobContinue = false; //작업종료인 경우 false 리턴
} else {
System.out.println("잘못된 값이 입력되었습니다."
+ " 메뉴(0~3) 숫자만 선택하세요");
}
return jobContinue;
}
private void showMenu() {
System.out.println("------------------------");
System.out.println("1.입금 2.출금 3.통장확인 0.종료");
System.out.println("------------------------");
System.out.print(">>작업선택 : ");
}
private void inputMoney() {
while (true) {
System.out.print(">>입금액 : ");
try {
money += Integer.parseInt(sc.nextLine());
} catch (NumberFormatException e) {
System.out.println("잘못된 값이 입력되었습니다."
+ " 숫자(0~9)만 입력하세요"
+ "\n다시 작업선택하세요.");
continue;
}
break;
}
}
private void outputMoney() {
while (true) {
System.out.print(">>출금액 : ");
try {
money -= Integer.parseInt(sc.nextLine());
} catch (NumberFormatException e) {
System.out.println("잘못된 값이 입력되었습니다."
+ " 숫자(0~9)만 입력하세요"
+ "\n다시 작업선택하세요.");
continue;
}
break;
}
}
private void showMoney() {
System.out.println(">>통장금액 : " + money + "원");
}
}