Logout

May 2015 Library Bookloans


Student.java
1    package may2015_library_bookloans; 
2     
3    import java.util.*; 
4    public class Student 
5    { 
6        private int studentID; 
7        private String studentName; 
8        private Loan[] booksBorrowed = new Loan[10]; 
9        private int numBooks = 0; 
10       public Student(int studentID, String studentName) 
11       { 
12           this.studentID=studentID; 
13           this.studentName=studentName; 
14       } 
15       public Loan getLoan (int x) 
16       { 
17           return this.booksBorrowed[x]; 
18       } 
19       public void addLoan(Loan book) 
20       { 
21           this.booksBorrowed[numBooks] = book; 
22           numBooks++; 
23       } 
24       public int getStudentID() 
25       { 
26           return this.studentID; 
27       } 
28       public String getStudentName() 
29       { 
30           return this.studentName; 
31       } 
32   }
Loan.java
1    package may2015_library_bookloans; 
2     
3    import java.util.*; 
4    public class Loan 
5    { 
6        private int bookID; 
7        private String bookTitle; 
8        private Date d; 
9        static int numBooksLoaned = 0; 
10       public Loan(int bookID, String bookTitle) 
11       { 
12           this.bookID = bookID; 
13           this.bookTitle = bookTitle; 
14           this.d = new Date(); //set date borrowed 
15           numBooksLoaned = numBooksLoaned +1; 
16       } 
17       public int getBookID() 
18       { 
19           return this.bookID; 
20       } 
21       public String getBookTitle() 
22       { 
23           return this.bookTitle; 
24       } 
25       public Date getDate() 
26       { 
27           return this.d; 
28       } 
29       public void setBookID(int id) 
30       { 
31           this.bookID = id; 
32       } 
33       public void setBookTitle(String title) 
34       { 
35           this.bookTitle = title; 
36       } 
37       public void setDate(Date d) 
38       { 
39           this.d = d; 
40       } 
41   } 
42   
MainForLibrary.java
1    package may2015_library_bookloans; 
2     
3    public class MainForLibrary { 
4     
5        public static void main(String[] args) { 
6            Student temp; 
7            Student[] borrowers = new Student[100000]; 
8            temp = new Student(93001, "Jones"); 
9            temp.addLoan(new Loan(210001, "The Sky")); 
10           borrowers[93001] = temp; 
11           temp = new Student(3012, "Zang"); 
12           temp.addLoan(new Loan(210121, "The Animals")); 
13           borrowers[3012] = temp; 
14           borrowers[93001].addLoan(new Loan(210002, "The Spooks")); 
15           temp = new Student(93002, "Nguyen"); 
16           temp.addLoan(new Loan(210011, "The Ocean")); 
17           borrowers[93002] = temp; 
18           System.out.println(borrowers[93001].getStudentName()); 
19           System.out.println(borrowers[93001].getLoan(1).getBookTitle()); 
20           System.out.println(borrowers[3012].getLoan(0).getBookTitle()); 
21    
22           System.out.println(borrowers[93001].getStudentName()); 
23           System.out.println(borrowers[93001].getLoan(1).getBookTitle()); 
24           System.out.println(borrowers[3012].getLoan(0).getBookTitle()); 
25       } 
26   } 
27