daily pastebin goal
49%
SHARE
TWEET

Untitled

a guest Jan 21st, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Emma Weil
  3. Segall
  4. AP Computer Science pd. 8
  5. 9/21/11
  6. This is a program to creates the Patron class so that patrons from this class may check out books while they are
  7. in the library class.
  8. */
  9.  
  10. public class Patron
  11. {
  12.     private Book book1;
  13.     private Book book2;
  14.     private Book book3;
  15.  
  16.     private String name;
  17.  
  18.     public Patron()
  19.     {
  20.         book1 = null;
  21.         book2 = null;
  22.         book3 = null;
  23.         name = null;
  24.     }
  25.  
  26.     public Patron(String theName)
  27.     {
  28.         book1 = null;
  29.         book2 = null;
  30.         book3 = null;
  31.         name = theName;
  32.     }
  33.  
  34.     public boolean hasBook(String title)
  35.     {
  36.         if(title.equals(book1.getTitle()) || title.equals(book2.getTitle()) || title.equals(book3.getTitle()))
  37.         {
  38.             return true;
  39.         }
  40.         else
  41.         {
  42.             return false;
  43.         }
  44.     }
  45.  
  46.     public boolean borrowBook(String title, String author)
  47.     {
  48.         if(book1==null)
  49.         {
  50.             book1 = new Book(title, author);
  51.             return true;
  52.         }
  53.         else if(book2==null)
  54.         {
  55.             book2 = new Book(title, author);
  56.             return true;
  57.         }
  58.         else if(book3==null)
  59.         {
  60.             book3 = new Book(title, author);
  61.             return true;
  62.         }
  63.         else
  64.         {
  65.             return false;
  66.         }
  67.     }
  68.  
  69.     public void returnBook(String title)
  70.     {
  71.         if(title.equals(book1.getTitle()))
  72.         {
  73.             book1 = null;
  74.         }
  75.  
  76.         else if (title.equals(book2.getTitle()))
  77.         {
  78.             book2 = null;
  79.         }
  80.  
  81.         else if(title.equals(book3.getTitle()))
  82.         {
  83.             book3 = null;
  84.         }
  85.     }
  86.  
  87.     public String toString()
  88.     {
  89.         return "Patron name: " + name + "\nBooks borrowed: \n" + book1 + "\n" + book2 + "\n" + book3;
  90.     }
  91.  
  92.  
  93. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top