-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMethodEx4Ref.java
More file actions
63 lines (53 loc) · 2.33 KB
/
Copy pathMethodEx4Ref.java
File metadata and controls
63 lines (53 loc) · 2.33 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
package method.ex;
import java.util.Scanner;
public class MethodEx4Ref {
public static void main(String[] args) {
int balance = 0;
Scanner scanner = new Scanner(System.in);
while(true) {
System.out.println("----------------------------------");
System.out.println("1.입금 | 2. 출금 | 3. 잔액확인 | 4. 종료");
System.out.println("----------------------------------");
System.out.print("선택 : ");
int choice = scanner.nextInt();
int amount;
switch (choice) {
case 1:
System.out.print("입금액을 입력하세요 : ");
amount = scanner.nextInt();
balance = deposit(balance, amount);
break;
case 2:
System.out.print("총 금액을 입력하세요 : ");
amount = scanner.nextInt();
balance = withdraw(balance, amount);
break;
case 3:
System.out.println("현재 잔액 : " + balance + "원");
break;
case 4:
System.out.println("시스템을 종료합니다.");
return;
default:
System.out.println("올바른 선택이 아닙니다. 다시 선택해주세요.");
break;
}
}
}
public static int deposit(int balance, int amount) {
balance += amount;
System.out.println(amount + "원을 입금하셨습니다. 현재 잔액 : " + balance + "입니다.");
return balance;
}
public static int withdraw(int balance, int withdrawAmount) {
if (balance >= withdrawAmount) {
balance -= withdrawAmount;
System.out.println(withdrawAmount + "원을 송금하셨습니다.. 현재 잔액: " + balance + "원");
return balance;
}
else {
System.out.println(withdrawAmount + "원을 송금하려 했으나 잔액이 부족합니다.");
return balance;
}
}
}