Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.69 KB | None | 0 0
  1. // Sample solution for HW2
  2. import java.time.LocalDate;
  3.  
  4. public class BookCopy {
  5.     public static final int BORROWING_WEEKS = 3;
  6.     public static final int RENEWAL_WEEKS = 2;
  7.     public static final double FINE_PER_DAY = .10;
  8.     private Book book;
  9.     private LibraryCard card;
  10.     private LocalDate dueDate;
  11.    
  12.     public BookCopy(Book b)
  13.     {
  14.         book = b;
  15.         card = null;
  16.         dueDate = null;
  17.     }
  18.    
  19.     public Book getBook() {return book;}
  20.     public String getTitle() {return book.getTitle();}
  21.     public LibraryCard getCard() {return card;}
  22.     public LocalDate getDueDate() {return dueDate;}
  23.    
  24.     public boolean checkOut(LibraryCard borrower, LocalDate dateOfBorrowing)
  25.    
  26.     /*checks book out by setting card reference to borrower.
  27.     returns false if book is already checked out
  28.     sets due date to BORROWING_WEEKS after current date passed */
  29.    
  30.     {
  31.         if (card != null)
  32.             return false;
  33.         card = borrower;
  34.         dueDate = dateOfBorrowing.plusWeeks(BORROWING_WEEKS);
  35.         return true;
  36.     }
  37.    
  38.     public boolean checkOut (LibraryCard borrower)
  39.     //default check out method that uses todays' date
  40.     {
  41.         return checkOut(borrower, LocalDate.now());
  42.     }
  43.    
  44.     public boolean returnBook()
  45.             //returns book by removing card reference
  46.             //returns false if there is no reference to a card
  47.     {
  48.         if (card == null)
  49.             return false;
  50.         card = null;
  51.         return true;
  52.     }
  53.    
  54.     public boolean renew (LocalDate renewalDate)
  55.     //renews book using RENEWAL_WEEKS as interval
  56.     //returns false if books is not checked out
  57.     {
  58.         if (card == null)
  59.             return false;
  60.         dueDate = renewalDate.plusWeeks(RENEWAL_WEEKS);
  61.         return true;
  62.     }
  63.    
  64.     public boolean renew ()
  65.     //default method uses todays date as renewal date
  66.     {
  67.         return renew(LocalDate.now());
  68.     }
  69.    
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement