-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathExercise07.java
More file actions
58 lines (52 loc) · 1.64 KB
/
Copy pathExercise07.java
File metadata and controls
58 lines (52 loc) · 1.64 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
import java.util.Scanner;
// 입력된 데이터로 예금, 출금, 조회, 종료 기능을 제공하는 코드
public class Exercise07 {
public static void main(String[] args) {
boolean run = true;
int menu = 0; // 메뉴 선택 변수
int balance = 0; // 예금액
int deposit, withdraw; // 입금, 출금
Scanner scanner = new Scanner(System.in);
while (run) {
System.out.println("---------------MENU----------------");
System.out.println(" 1.예금 | 2.출금 | 3.잔고 | 4.종료");
System.out.println("현재 예금액: " + balance + "원");
System.out.println("-----------------------------------");
System.out.print("선택 >>");
menu = scanner.nextInt();
switch(menu) {
case 1:
deposit = 0;
System.out.println("-----------------------------------");
System.out.println("예금할 금액을 입력하세요.");
System.out.print("금액 > ");
deposit = scanner.nextInt();
balance += deposit;
break;
case 2:
withdraw = 0;
System.out.println("-----------------------------------");
System.out.println("출금할 금액을 입력하세요.");
System.out.print("금액 > ");
withdraw = scanner.nextInt();
if(balance < withdraw) {
System.out.println("현재 예금액 보다 출금할 금액이 큽니다.");
continue;
}
balance -= withdraw;
break;
case 3:
System.out.println("-----------------------------------");
System.out.println("현재 예금액은 " + balance + "원 입니다.");
break;
case 4:
run = false;
break;
default:
System.out.println("잘못된 메뉴를 선택하셨습니다.");
break;
}
}
System.out.println("프로그램 종료");
}
}