-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccount2.java
141 lines (123 loc) · 4.8 KB
/
Account2.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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import java.util.Scanner;
public class Account2 {
private String ano;
private String owner;
private int balance;
public Account2(String ano, String owner, int balance) {
this.ano = ano;
this.owner = owner;
this.balance = balance;
}
public String getAno() { return ano;}
public void setAno(String ano) { this.ano = ano;}
public String getOwner() { return owner;}
public void setOwner(String owner) { this.owner = owner;}
public int getBalance() { return balance;}
public void setBalance(int balance) {this.balance = balance;}
}
class BankApplication {
private static Account2[] accountArray = new Account2[100];
private static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
boolean run = true;
while(run) {
System.out.println("----------------------------------------------------------");
System.out.println("1.계좌생성 | 2.계좌목록 | 3.예금 | 4.출금 | 5.종료");
System.out.println("----------------------------------------------------------");
System.out.print("선택> ");
int selectNo = scanner.nextInt();
if (selectNo == 1) {
createAccount();
} else if (selectNo == 2) {
accountList();
} else if (selectNo == 3) {
deposit();
} else if (selectNo == 4) {
withdraw();
} else if (selectNo == 5) {
run = false;
}
}
System.out.println("프로그램 종료");
}
private static void createAccount() {
System.out.println("--------------");
System.out.println("계좌생성");
System.out.println("--------------");
System.out.print("계좌번호: ");
String ano = scanner.next();
System.out.print("계좌주: ");
String owner = scanner.next();
System.out.print("초기입금액: ");
int balance = scanner.nextInt();
Account2 newAccount = new Account2(ano, owner, balance);
for (int i = 0; i < accountArray.length; i++) {
if (accountArray[i] == null) {
accountArray[i] = newAccount;
System.out.println("결과 : 계좌가 생성되었습니다.");
break;
}
}
}
private static void accountList() {
System.out.println("--------------");
System.out.println("계좌목록");
System.out.println("--------------");
for (int i = 0; i < accountArray.length; i++) {
Account2 account = accountArray[i];
if (account != null) {
System.out.print(account.getAno());
System.out.print(" ");
System.out.print(account.getOwner());
System.out.print(" ");
System.out.print(account.getBalance());
System.out.println();
}
}
}
private static void deposit() {
System.out.println("--------------");
System.out.println("예금");
System.out.println("--------------");
System.out.print("계좌번호: ");
String ano = scanner.next();
System.out.println("예금액 : ");
int money = scanner.nextInt();
Account2 account = findAccount(ano);
if (account == null) {
System.out.println("결과 : 계좌가 없습니다.");
return;
}
account.setBalance(account.getBalance() + money);
System.out.println("결과 : 예금이 성공되었습니다.");
}
private static void withdraw() {
System.out.println("--------------");
System.out.println("출금");
System.out.println("--------------");
System.out.print("계좌번호: ");
String ano = scanner.next();
System.out.print("출금액: ");
int money = scanner.nextInt();
Account2 account = findAccount(ano);
if (account == null) {
System.out.println("결과 : 계좌가 없습니다.");
return;
}
account.setBalance((account.getBalance() - money));
System.out.println("결과 : 출금이 성공되었습니다.");
}
private static Account2 findAccount(String ano) {
Account2 account = null;
for (int i = 0; i <accountArray.length; i++) {
if (accountArray[i] != null) {
String dbAno = accountArray[i].getAno();
if (dbAno.equals(ano)) {
account = accountArray[i];
break;
}
}
}
return account;
}
}