// 문제1

class Account
{
 String accountNo;
 String ownerName;
 int balance;
 Account(String accountNo, String ownerName, int balance)
 {
  this.accountNo = accountNo;
  this.ownerName = ownerName;
  this.balance = balance;
 }
 
 void deposit(int amount)
 {
  balance += amount;
 }
 int withdraw(int amount) throws Exception
 {
  if(balance < amount)
   throw new Exception("잔액 부족");
  balance -= amount;
  return amount;
 }
}

class CheckingAccount extends Account
{
 String cardNo;
 CheckingAccount(String accountNo, String ownerName, int balance, String candNo)
 {
  super(accountNo, ownerName, balance);
  this.cardNo = candNo;
 }
 int pay(String cardNo, int amount) throws Exception
 {
  if(!cardNo.equals(this.cardNo) || (balance < amount))
   throw new Exception("지불 불가");
 
  return withdraw(amount);
 }
}

public class test
{
 public static void main(String[] args)
 {
  Account obj1 = new Account("111-22-33333","임꺽정",10000);
  Account obj2 = new Account("777-88-99999","김선달",30000);
  Account obj3 = new CheckingAccount("444-55-66666","홍길동",20000,"5555-6666-77777-8888");
  Account obj4 = new Account("000-00-00000","김미영",0);
 
  printAccountInfo(obj1);
  printAccountInfo(obj2);
  printAccountInfo(obj3);
  printAccountInfo(obj4);
 }
 
 static void printAccountInfo(Account obj)
 {
  System.out.println("계좌번호 : "+obj.accountNo);
  System.out.println("예금주 이름 : "+obj.ownerName);
  System.out.println("잔액 : "+obj.balance);
  if(obj instanceof CheckingAccount)
  {
   CheckingAccount CAobj = (CheckingAccount)obj;
   System.out.println("카드번호 : " + CAobj.cardNo);
  }
  System.out.println();
 }
}

// 문제 2번
enum Color
{
 YELLOW("노랑"), RED("빨강"), BLUE("파랑");
 final private String name;
 Color(String name)
 {
  this.name = name;
 }
 String value()
 {
  return name;
 }
}

// 문제 3
enum State
{
 BORROWED(1), NORMAL(0);
 final private int state;
 State(int state)
 {
  this.state = state;
 }
 int value()
 {
  return state;
 }
}

class SeparateVolume
{
 String requestNo;
 String bookTitle;
 String writer;
 String borrower;
 String checkOutData;
 State state;
 SeparateVolume(String requno, String book, String writer)
 {
  this.requestNo = requno;
  this.bookTitle = book;
  this.writer = writer;
 }
 public void checkOut(String borrower, String data)//대출함
 {
  if(state.value()!= state.NORMAL)
   return;
  this.borrower = borrower;
  this.checkOutData = data;
  this.state = state.BORROWED;
  System.out.println("*"+ bookTitle + "이(가) 대출되었음");
  System.out.println("대출인 : "+ borrower);
  System.out.println("대출일 : "+ checkOutData);
 }
 
 public void checkID()       // 반납
 {
  this.borrower = null;
  this.checkOutData = null;
  this.state = state.NORMAL;
  System.out.println("*"+ bookTitle + "이(가) 반납되었음");
 }
}

+ Recent posts