@챈챈/#Other
[JAVA] 은행 프로그램
자바장인
2020. 2. 20. 14:52
안녕하세요 자바 악개입니다. 사실 자바보다 다른 게 더 좋지만 사는 게 다 그렇습니다.
오늘은 사칙연산을 기반으로 한 간단한 은행 기기입니다.
뭐든 쉬운 게 최고예요.
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
|
import java.util.Scanner;
public class Bank {
int money = 0;
public void printMenu()
{
System.out.println("-------------------------------------");
System.out.println("1.입금 | 2.출금 | 3.잔고 | 4.종료");
System.out.println("-------------------------------------");
System.out.print("선택 > ");
}
public void deposit()
{
Scanner scan = new Scanner(System.in);
int temp = 0;
System.out.print("예금액 > ");
temp = scan.nextInt();
money += temp;
}
public void withdrawal()
{
Scanner scan = new Scanner(System.in);
int temp = 0;
System.out.print("출금액 > ");
temp = scan.nextInt();
if(temp>money)
{
System.out.println("잔액이 부족합니다.");
}
else
{
money -= temp;
}
}
public void balance()
{
System.out.print("잔고 > ");
System.out.println(money);
}
public void choiceMenu()
{
int selection = 0;
do
{
Scanner scan = new Scanner(System.in);
printMenu();
selection = scan.nextInt();
switch(selection)
{
case 1:
{
deposit();
}
break;
case 2:
{
withdrawal();
}
break;
case 3:
{
balance();
}
break;
case 4:
{
System.out.println("종료합니다.");
}
break;
default :
{
System.out.println("잘못 입력하셨습니다.");
}
break;
}
} while(selection != 4);
}
public static void main(String args[])
{
Bank bank = new Bank();
bank.choiceMenu();
}
}
|