daily pastebin goal
36%
SHARE
TWEET

Untitled

a guest Jan 21st, 2019 54 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/23/11
  6. This is a program to creates the Library class that will serve as an interface for the Book/Patron classes.
  7.  
  8. */
  9.  
  10. import TerminalIO.KeyboardReader;
  11. public class Library{
  12.        
  13.     public static void main(String [] args){
  14.        
  15.         KeyboardReader reader = new KeyboardReader();
  16.        
  17.         Patron p1 = new Patron("Joshua"); /// This one is Bob because I don't really like the name Bob
  18.         Patron p2 = new Patron("Alec"); /// This one is Jim because I don't really like the name Jim, either
  19.        
  20.         String title = "";
  21.         String author = "";
  22.         String name = "";
  23.         int ans = 0;
  24.        
  25.     while(true)
  26.     {
  27.    
  28.             name = reader.readLine("What is your name, patron? ('no one' to quit) ");
  29.             if (name.equals("no one"))
  30.             {
  31.                 break;
  32.             }
  33.             while (name.equals("Joshua"))
  34.             {
  35.                 ans = reader.readInt("Would you like to check out a book? (1 for yes, 0 for no) ");
  36.                 if (ans!=1)
  37.                 {
  38.                     break;
  39.                 }
  40.                
  41.                
  42.                
  43.                 title = reader.readLine("What is the title of the book you would like to check out? ");
  44.                 author = reader.readLine("What is the author of the book you would like to check out? ");
  45.                
  46.                 System.out.println();
  47.                
  48.                 while ( p1.borrowBook(title, author) == false)
  49.                 {
  50.                     System.out.println("You cannot borrow any more books. Please return a book first.");
  51.                    
  52.                     System.out.println("\nThe books you have checked out currently are: \n" + p1);
  53.                    
  54.                     title = reader.readLine("What is the title of the book you would like to return? ");
  55.                    
  56.                    
  57.                         while (p1.hasBook(title) == false)
  58.                         {
  59.                             System.out.println("You haven't checked that book out, so you can't return it. ");
  60.                             title = reader.readLine("What is the title of the book you would like to return? /n (Type 'none' if you would not like to return anything,/nkeeping in mind you will not be able to check out another book until you return one) ");
  61.                             if (title.equals("none"))
  62.                             {
  63.                                 break;
  64.                             }
  65.                         }
  66.                        
  67.                     p1.returnBook(title);
  68.                     System.out.println("Okay, you have room to borrow another book. ");
  69.                     title = reader.readLine("What is the title of the book you would like to check out? ");
  70.                     author = reader.readLine("What is the author of the book you would like to check out? ");
  71.                     System.out.println();
  72.                 }
  73.                
  74.             }
  75.            
  76.             if (name.equals("Joshua"))
  77.             {
  78.                 System.out.println();
  79.                 System.out.println("Goodbye, " + name);
  80.             }
  81.            
  82.             while (name.equals("Alec"))
  83.             {
  84.                 ans = reader.readInt("Would you like to check out a book? (1 for yes, 0 for no) ");
  85.                 if (ans!=1)
  86.                 {
  87.                     break;
  88.                 }
  89.                
  90.                
  91.                
  92.                 title = reader.readLine("What is the title of the book you would like to check out? ");
  93.                 author = reader.readLine("What is the author of the book you would like to check out? ");
  94.                
  95.                 System.out.println();
  96.                
  97.                 while ( p2.borrowBook(title, author) == false)
  98.                 {
  99.                     System.out.println("You cannot borrow any more books. Please return a book first.");
  100.                    
  101.                     System.out.println("\nThe books you have checked out currently are: \n" + p2);
  102.                    
  103.                     title = reader.readLine("What is the title of the book you would like to return? ");
  104.                    
  105.                    
  106.                         while (p2.hasBook(title) == false)
  107.                         {
  108.                             System.out.println("You haven't checked that book out, so you can't return it. ");
  109.                             title = reader.readLine("What is the title of the book you would like to return? /n (Type 'none' if you would not like to return anything,/nkeeping in mind you will not be able to check out another book until you return one) ");
  110.                             if (title.equals("none"))
  111.                             {
  112.                                 break;
  113.                             }
  114.                         }
  115.                        
  116.                     p2.returnBook(title);
  117.                     System.out.println("Okay, you have room to borrow another book. ");
  118.                     title = reader.readLine("What is the title of the book you would like to check out? ");
  119.                     author = reader.readLine("What is the author of the book you would like to check out? ");
  120.                     System.out.println();
  121.                 }
  122.                
  123.             }
  124.            
  125.             if (name.equals("Alec"))
  126.             {
  127.                 System.out.println();
  128.                 System.out.println("Goodbye, " + name);
  129.             }
  130.     }
  131.        
  132.     }
  133. }
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