방치하기

홍대 자바 수업 .도서관 객체 . 인터페이스 와 상속 본문

홍익대 Java/수업

홍대 자바 수업 .도서관 객체 . 인터페이스 와 상속

Yi Junho 2009. 7. 24. 16:21
반응형
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
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();    
    }
}
반응형
Comments