ํฐ์คํ ๋ฆฌ ๋ทฐ
package jbank;
import java.io.*;
public class AccountMain {
public static void main(String[] ar) throws NumberFormatException, IOException {
AccountManager jbank = new AccountManager();
BufferedReader in = new BufferedReader (new InputStreamReader (System.in));
while(true) {
jbank.printMenu();
System.out.print("์ ํ: ");
int choice = Integer.parseInt(in.readLine());
switch (choice) {
case 1: jbank.makeAccount(); break; // ๊ณ์ข๊ฐ์ค
case 2: jbank.inMoney(); break; // ์
๊ธ
case 3: jbank.outMoney(); break; // ์ถ๊ธ
case 4: jbank.showMoney(); break; // ์์ก์กฐํ
case 5: System.out.println("๊ฐ์ฌํฉ๋๋ค."); return;
default: System.out.println("์ ํ์ ์๋ชปํ์
จ์ต๋๋ค.");
}
}
}
}
==========================================================================================================================================
package jbank;
import java.io.*;
public class AccountManager {
Account[] array = new Account[100];
int index;
BufferedReader in;
public AccountManager() {
index = 0;
}
public void printMenu() {
System.out.println("====== Menu ======");
System.out.println("1. ๊ณ์ข๊ฐ์ค");
System.out.println("2. ์
๊ธ");
System.out.println("3. ์ถ๊ธ");
System.out.println("4. ์์ก์กฐํ");
System.out.println("5. ํ๋ก๊ทธ๋จ ์ข
๋ฃ");
System.out.println("====== Bye ======");
}
public void makeAccount() throws IOException { //๊ณ์ข๊ฐ์คํ๊ธฐ
in = new BufferedReader (new InputStreamReader (System.in));
System.out.println("๊ณ์ข๊ฐ์ค ====== ");
System.out.println("๊ณ์ข๋ฒํธ : ");
int id = Integer.parseInt(in.readLine());
System.out.println("์ด๋ฆ : ");
String name = in.readLine();
System.out.println("์
๊ธ์ก : ");
int balance = Integer.parseInt(in.readLine());
array[index++] = new Account(id, balance, name);
}
public void inMoney() throws IOException { //์
๊ธํ๊ธฐ
in = new BufferedReader (new InputStreamReader (System.in));
System.out.print("๊ณ์ข ID : ");
int id = Integer.parseInt(in.readLine());
System.out.println("์
๊ธ์ก : ");
int money = Integer.parseInt(in.readLine());
for (int i = 0; i < index; i++) {
if(array[i].getId() == id) {
array[i].addMoney(money);
System.out.println("์
๊ธ์๋ฃ!!!");
return;
}
}
System.out.println("์ ํจํ์ง ์์ ID ์
๋๋ค.");
}
public void outMoney() throws IOException { //์ถ๊ธํ๊ธฐ
in = new BufferedReader (new InputStreamReader (System.in));
System.out.print("๊ณ์ข ID : ");
int id = Integer.parseInt(in.readLine());
System.out.println("์ถ๊ธ์ก : ");
int money = Integer.parseInt(in.readLine());
for (int i = 0; i < index; i++) {
if(array[i].getId() == id) {
if(array[i].getBalance() < money) {
System.out.println("์์ก๋ถ์กฑ");
return;
}
array[i].minMoney(money);
System.out.println("์ถ๊ธ์๋ฃ!!!");
return;
}
}
System.out.println("์ ํจํ์ง ์์ ID ์
๋๋ค.");
}
public void showMoney() throws IOException { //์์ก์กฐํ
in = new BufferedReader (new InputStreamReader (System.in));
System.out.print("๊ณ์ข ID : ");
int id = Integer.parseInt(in.readLine());
for(int i = 0; i < index; i++) {
if(array[i].getId() == id) {
array[i].showData();
}
}
}
}
==========================================================================================================================================
package jbank;
public class Account {
private int id; //๊ณ์ข๋ฒํธ
private int balance; //์์ก
private String name; //์ด๋ฆ
public Account(int id, int balance, String name) { //์์ฑ์
this.id = id;
this.balance = balance;
this.name = name;
}
public int getId() {
return id;
}
public int getBalance() {
return balance;
}
public void addMoney(int value) { //์
๊ธ
balance += value;
}
public void minMoney(int value) { //์ถ๊ธ
balance -= value;
}
public void showData() { //๊ณ์ข์ ๋ณด ๋ณด์ฌ์ฃผ๊ธฐ
System.out.println("๊ณ์ข๋ฒํธ : " + id);
System.out.println("์ด๋ฆ : " + name);
System.out.println("์์ก : " + balance);
}
}
'PROGRAMMING' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์ด๊ฒ์ด ์ค์์ธ๊ฑฐ์ผ? (0) | 2010.05.29 |
---|---|
๋ก๋์์ฑ๊ธฐ ใ ใ (0) | 2010.05.15 |
ํ๋ก๊ทธ๋๋จธ์ ์๊ธฐ์ฌ์ฐ๊ธฐ... (0) | 2009.10.15 |
kakao ์นด์นด์ค๋ท์ปด (2) | 2009.10.09 |
css ์ฝ๋ฉ. (0) | 2009.05.09 |
- Total
- Today
- Yesterday
- Ajax
- JSP
- ์น์์ด์ ์
- MySQL
- ๋ฉ๋ฐฐํ
- ๊ฒฝ์ ์ฉ์ด
- asp
- EL
- ์๋ฐ์คํฌ๋ฆฝํธ
- JS
- php
- ์๋ฆฌ
- I Don't Care
- JavaScript
- ํจ์
- Java
- JSON
- ์๋ธ๋ฆฟ
- Servlet
- ๋ณต๊ทผ์ด๋
- ๊ธฐํ
- ์ธํจ์ด
- ์นด๋ฐ์จ๋ผ์ธ
- 8๋ง์ผ
- jQuery
- JSTL
- MS-SQL
- ๋์ค
- 2ne1
- ์์์ฌ์ด๋
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |