All pastes #563447 Raw Edit

projket

public java v1 · immutable
·published 2007-06-13 04:12 UTC
rendered paste body
// ITI 11121 Summer 2007, Assignment 2// Name: Mike Kelly, Student# 4676728import java.io.*;import javax.swing.JOptionPane;//Library classpublic class Library {  private LinkedList readerList;  private LinkedList bookList;    //a method to add a reader to the end of the linkedlist readerList. Instance method.  public void addReader(Reader r){    readerList = readerList.insertLast(r);  }  //a method to add a book to the end of linkedlist bookList.  Instance method.  public void addBook(Book b){    bookList = bookList.insertLast(b);  }    public void borrowBook(Reader r, Book b, Date aDay){    //first we must check the status of this book- is it in the library?    if(b.getBorrower() == null){      //yes it is in the library because no one is currently borrowing it.      r.processBorrow(b);      b.processBorrow(r,aDay);    } }  public void returnBook(Book b, Date aDay){    //first- output an error msg if the book is currently in the library.    if(!(b.getBorrower() == null)){      System.out.println("Error!" + b + " is in library.  It cannot be returned by a reader.");    }    else{      int days = b.processReturn(aDay);      b.getBorrower().processReturn(b, days);    }  }  }//////////////////////////////////////////////////////////////////////******************************************************************//******************************************************************//******************************************************************// TEST CLASSpublic class LibraryTest{ public static void main (String [ ] args) {  Library lib = new Library ( );    Reader reader1 = new Faculty (101, "SITE"), reader2 = new Faculty (102, "MATH"),       reader3 = new Student (103, "MBA"), reader4 = new Student (105, "BCS");          Book book1 = new Book (201), book2 = new Book (202), book3 = new Book (203),    book4 = new Book (204), book5 = new Book (205), book6 = new Book (206),    book7 = new Book (207), book8 = new Book (208), book9 = new Book (209);    Faculty.setFacultyLimit (3);  Faculty.setFacultyTerm (5);  Student.setStudentLimit (2);  Student.setStudentTerm (3);    lib.addReader (reader1).addReader (reader2).addReader (reader3).addReader (reader4).   addBook (book1).addBook (book2).addBook (book3).   addBook (book4).addBook (book5).addBook (book6).   addBook (book7).addBook (book8).addBook (book9);    lib.borrowBook (reader1, book1, new Date (2007, 5, 1))   .borrowBook (reader1, book2, new Date (2007, 5, 1))   .borrowBook (reader1, book3, new Date (2007, 5, 1))   .borrowBook (reader1, book4, new Date (2007, 5, 1)) // over the limit   .borrowBook (reader2, book1, new Date (2007, 5, 2)) // not available   .borrowBook (reader2, book4, new Date (2007, 5, 2))   .borrowBook (reader2, book5, new Date (2007, 5, 2))   .borrowBook (reader3, book6, new Date (2007, 5, 3))   .borrowBook (reader3, book2, new Date (2007, 5, 3)) // not available   .borrowBook (reader3, book7, new Date (2007, 5, 3))    .borrowBook (reader3, book8, new Date (2007, 5, 3)) // over the limit   .borrowBook (reader4, book8, new Date (2007, 5, 4));    reader1.printWithBooksBorrowed ( );  reader2.printWithBooksBorrowed ( );  reader3.printWithBooksBorrowed ( );  reader4.printWithBooksBorrowed ( );   lib.returnBook (book4, new Date (2007, 5, 3))   .returnBook (book1, new Date (2007, 5, 4))   .returnBook (book7, new Date (2007, 5, 5))   .returnBook (book8, new Date (2007, 5, 9))   .returnBook (book9, new Date (2007, 5, 10));       reader1.printWithBooksBorrowed ( );  reader2.printWithBooksBorrowed ( );  reader3.printWithBooksBorrowed ( );  reader4.printWithBooksBorrowed ( );  lib.returnBook (book2, new Date (2007, 5, 10))   .returnBook (book5, new Date (2007, 5, 10))   .returnBook (book3, new Date (2007, 5, 10))     .returnBook (book6, new Date (2007, 5, 10))   .returnBook (book3, new Date (2007, 5, 15));     lib.borrowBook (reader1, book3, new Date (2007, 5, 1))   .borrowBook (reader1, book9, new Date (2007, 5, 1))   .borrowBook (reader1, book1, new Date (2007, 5, 1))   .borrowBook (reader2, book4, new Date (2007, 5, 1))    .borrowBook (reader3, book5, new Date (2007, 5, 2))   .borrowBook (reader3, book6, new Date (2007, 5, 2));  reader1.printWithBooksBorrowed ( );  reader2.printWithBooksBorrowed ( );  reader3.printWithBooksBorrowed ( );  reader4.printWithBooksBorrowed ( );    reader1.payFine (4.0);  reader2.payFine (1.0);  reader3.payFine (2.0);  reader4.payFine (1.0);  reader1.printWithBooksBorrowed ( );  reader2.printWithBooksBorrowed ( );  reader3.printWithBooksBorrowed ( );  reader4.printWithBooksBorrowed ( ); }}