MainClass.java
public class MainClass {
	public static void main(String[] args) {

		basicFunc start = new basicFunc();
		start.play();
	}
}
BasicFunc.java
import java.util.Scanner;

class BasicFunc {
	void play() {
		String name;
		String accountNo;
		int limit;
		System.out.println("사용자메뉴");
		Scanner in = new Scanner(System.in);
		loop: while (true) {
			System.out.println("1. 일반 통장 개설");
			System.out.println("2. 마이너스 통장 개설");
			System.out.println("3. 종료");
			System.out.print("->");
			int chk = in.nextInt();
//			try {
				in.nextLine();
				switch (chk) {
				case 1:
					System.out.println("일반 통장 개설");
					System.out.print("이름 : ");
					name = in.nextLine();
					System.out.print("계좌번호 : ");
					accountNo = in.nextLine();
					System.out.println(name + ", " + accountNo);
					try{
					Account person = new Account(name, accountNo);
					person.play();
					}catch(Exception e) {
						System.out.println(e.getMessage());
					}
				
					
					
					break;
				case 2:
					System.out.println("마이너스 일반 통장 개설");
					System.out.print("이름 : ");
					name = in.nextLine();
					System.out.print("계좌번호 : ");
					accountNo = in.nextLine();
					System.out.print("한도 : ");
					limit = in.nextInt();
//					Account personM = new AccountM(name, accountNo, limit);
//					personM.play();
					break;
				case 3:
					break loop;
				default:
					System.out.println("다시 입력해주세요.");

				}
//			} catch (Exception e) {
//				System.out.println(e.getMessage());
//			}
		}
		System.out.println("system quit..");
	}
}
Account.java
import java.util.Scanner;

public class Account {
	String name; // 예금주 이름
	String accountNo; // 계좌번호
	int balance; // 잔고

	// 생성자
	Account() {
	}

	Account(String name, String accountNo) throws Exception {
		if(name.equals("\n") || accountNo.equals(null)) {
			System.out.println("값 없음");
			throw new Exception("값을 모두 입력하세요.");
		}
		this.name = name;
		this.accountNo = accountNo;
	}

	// ----------------------
	// 생성자 끝

	void play() {
		Scanner in = new Scanner(System.in);
//		System.out.print("이름 : ");
//		this.name = in.nextLine();
//		System.out.print("계좌번호 : ");
//		this.accountNo = in.nextLine();
		int temp;
		int chk = 1;
		loop: while (chk != 0) {
			try {
				System.out.println("1. 입금, 2. 출금, 3. 정보, 0. 종료");
				System.out.print("->");
				int num = in.nextInt();
				switch (num) {
				case 1:
					System.out.print("입금얼마?");
					temp = in.nextInt();
					inputMoney(temp);
					break;
				case 2:
					System.out.print("출금얼마?");
					temp = in.nextInt();
					outputMoney(temp);
					break;
				case 3:
					infoPrint();
					break;
				case 0:
					break loop;
				default:
					System.out.println("다시입력하시오");
				}

			} catch (Exception e) {
				System.out.println(e.getMessage());
			}
		}
	}

	void infoPrint() {
		System.out.println("이름 : " + name);
		System.out.println("게좌 : " + accountNo);
		System.out.println("잔액 : " + balance);
	}

	void inputMoney(int amount) {
		this.balance += amount;
		System.out.println(amount + "원을 입금하고, 잔액은 " + balance + "원입니다.");
	}

	void outputMoney(int amount) throws Exception {
		if (balance < amount) {
			throw new Exception("잔액이 부족합니다.");
		} else {
			balance -= amount;
			System.out.println(amount + "원을 인출하고, 잔액은 " + balance + "원입니다.");
		}
	}

	void calculateInterest() {

	}
}
AccountM.java
import java.util.Scanner;

public class AccountM extends Account {
	int limit = 0; // 마이너스 한도

	// 생성자
	AccountM() {
		// 기본 한도 500만원.
		this.limit = 500;
	}

	AccountM(String name, String accountNo, int limit) throws Exception {
		super(name, accountNo);
		this.limit = limit;
	}

	// ----------------------
	// 생성자 끝

	void play() {
		Scanner in = new Scanner(System.in);
		System.out.print("이름 : ");
		this.name = in.nextLine();
		System.out.print("계좌번호 : ");
		this.accountNo = in.nextLine();
		System.out.print("한도 : ");
		this.limit = in.nextInt();
		int temp;
		int chk = 1;
		loop: while (chk != 0) {
			try {
				System.out.println("1. 입금, 2. 출금, 3. 정보, 0. 종료");
				System.out.print("->");
				int num = in.nextInt();
				switch (num) {
				case 1:
					System.out.print("얼마?");
					temp = in.nextInt();
					inputMoney(temp);
					break;
				case 2:
					System.out.print("얼마?");
					temp = in.nextInt();
					outputMoney(temp);
					break;
				case 3:
					infoPrint();
					break;
				case 0:
					break loop;
				default:
					System.out.println("다시입력하시오");
				}

			} catch (Exception e) {
				System.out.println(e.getMessage());
			}
		}
	}

	// 오버라이딩
	void infoPrint() {
		System.out.println("이름1 : " + name);
		System.out.println("게좌 : " + accountNo);
		System.out.println("한도금액 : " + limit);
		System.out.println("잔고 : " + balance);
		System.out.println("인출가능잔액 : " + (balance + limit));
	}

	void inputMoney(int amount) {
		this.balance += amount;
		System.out.println(amount + "원을 입금하고, 잔액은 " + (balance + limit)
				+ "원입니다.");
	}

	// 오버라이딩
	void outputMoney(int amount) throws Exception {
		if ((balance + limit) < amount) {
			throw new Exception("잔액이 부족합니다.");
		} else {
			balance -= amount;
			System.out.println(amount + "원을 인출하고, 인출가능잔액은 " + (balance + limit)
					+ "원입니다.");
		}
	}
}


'대학 생활 > JAVA' 카테고리의 다른 글

[JAVA] ArrayList, LinkedList, Stack, Queue  (0) 2014.01.09
[JAVA] 계산기  (0) 2014.01.05
[JAVA] * 별 출력하기_10 다이아몬드  (0) 2013.11.15
[JAVA] * 별 출력하기_09 마름모  (0) 2013.11.14

+ Recent posts