홍익대 Java/수업
홍대 자바 수업 .도서관 객체 . 인터페이스 와 상속
Yi Junho
2009. 7. 24. 16:21
반응형
interface Lendable { abstract void checkOut(String borrower, String date); abstract void checkIn(); } class SeparateVolume implements Lendable { String requestNo; // 청구번호 String bookTitle; // 제목 String writer; // 저자 String borrower; // 대출인 String checkOutDate; // 대출일 byte state; // 대출상태 SeparateVolume(String requestNo, String bookTitle, String writer) { this.requestNo = requestNo; this.bookTitle = bookTitle; this.writer = writer; } public void checkOut(String borrower, String date) { // 대출한다 if (state != 0) return; this.borrower = borrower; this.checkOutDate = date; this.state = 1; System.out.println("*" + bookTitle + " 이(가) 대출되었습니다."); System.out.println("대출인:" + borrower); System.out.println("대출일:" + date + "\n"); } public void checkIn() { // 반납한다 this.borrower = null; this.checkOutDate = null; this.state = 0; System.out.println("*" + bookTitle + " 이(가) 반납되었습니다.\n"); } } class CDInfo { String registerNo; // 관련번호 String title; // 타이틀 CDInfo(String registerNo, String title) { this.registerNo = registerNo; this.title = title; } } class AppCDInfo extends CDInfo implements Lendable { String borrower; // 대출인 String checkOutDate; // 대출일 byte state; // 대출상태 AppCDInfo(String registerNo, String title) { super(registerNo, title); } public void checkOut(String borrower, String date) { // 대출한다 if (state != 0) return; this.borrower = borrower; this.checkOutDate = date; this.state = 1; System.out.println("*" + title + " CD가 대출되었습니다."); System.out.println("대출인:" + borrower); System.out.println("대출일:" + date + "\n"); } public void checkIn() { // 반납한다 this.borrower = null; this.checkOutDate = null; this.state = 0; System.out.println("*" + title + " CD가 반납되었습니다.\n"); } } class Dictionary { String title; String registerNo; Dictionary(String registerNo,String title) { this.title = title; this.registerNo = registerNo; } } class AppDic extends Dictionary implements Lendable { String borrower; // 대출인 String checkOutDate; // 대출일 String chul; byte state; // 대출상태 AppDic(String registerNo, String title,String chul) { super(registerNo, title); this.chul=chul; } public void checkOut(String borrower, String date) { // 대출한다 if (state == 1) return; this.borrower = borrower; this.checkOutDate = date; this.state = 1; System.out.println("*" + title+" 출판사:"+chul + " 사전이 대출되었습니다."); System.out.println("대출인:" + borrower); System.out.println("대출일:" + date + "\n"); } public void checkIn() { // 반납한다 this.borrower = null; this.checkOutDate = null; this.state = 0; System.out.println("*" + title + " 사전이 반납되었습니다.\n"); } } class InterfaceExample1 { public static void main(String args[]) { SeparateVolume obj1 = new SeparateVolume("863ㅂ774개", "개미", "베르베르"); AppCDInfo obj2 = new AppCDInfo("2005-7001", "Redhat Fedora"); AppDic obj3= new AppDic("2005-7001", "영한사전", "동아"); obj1.checkOut("김영숙", "20060315"); obj2.checkOut("박희경", "20060317"); obj3.checkOut("이준호", "20060315"); obj1.checkIn(); obj2.checkIn(); } }
반응형