Advertisement
Guest User

Untitled

a guest
Jun 8th, 2012
616
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.*;
  2.  
  3. public class Client {
  4.     //Used for all input
  5.     public static Scanner input = new Scanner(System.in);
  6.    
  7.     //3 Book objects
  8.     public static Book b1, b2, b3;
  9.    
  10.     //String variables for the title and author of each book
  11.     public static String b1Title, b1Author;
  12.     public static String b2Title, b2Author;
  13.     public static String b3Title, b3Author;
  14.    
  15.     //Patron object
  16.     public static Patron customer;
  17.    
  18.     //Get initial book information
  19.     private static void getInformation(){
  20.         //Book 1 information
  21.         System.out.println("Please enter title of book 1: ");
  22.         b1Title = input.nextLine();
  23.         System.out.println("Please enter author of book 1: ");
  24.         b1Author = input.nextLine();
  25.         b1 = new Book(b1Title, b1Author);
  26.        
  27.         //Book 2 information
  28.         System.out.println("Please enter title of book 2: ");
  29.         b2Title = input.nextLine();
  30.         System.out.println("Please enter author of book 2:");
  31.         b2Author = input.nextLine();
  32.         b2 = new Book(b2Title, b2Author);
  33.        
  34.         //Book 3 information
  35.         System.out.println("Please enter title of book 3: ");
  36.         b3Title = input.nextLine();
  37.         System.out.println("Please enter author of book 3:");
  38.         b3Author = input.nextLine();
  39.         b3 = new Book(b3Title, b3Author);
  40.        
  41.         //Initialize the patron object
  42.         customer = new Patron(b1, b2, b3);
  43.     }
  44.    
  45.     //Take out a book
  46.     private static void takeOutBook(){
  47.         //Book info of book to take out
  48.         System.out.println("Would you like to take out a book? (1 yes or 2 no)");
  49.         int in = input.nextInt();
  50.         if(in == 1) {
  51.             System.out.println("Name of book to take out: ");
  52.             String bookTitle = input.nextLine();
  53.             System.out.println("Author of book to take out: ");
  54.             String bookAuthor = input.nextLine();
  55.        
  56.             //Check for open slots
  57.             if(customer.takeOut(bookTitle, bookAuthor)){
  58.                 System.out.println("The book " + bookTitle + " has been taken out");
  59.             } else {
  60.                 System.out.println("You must return a book before taking out another!");
  61.             }
  62.            
  63.         } else if((in != 1) || (in!= 2)){
  64.             System.out.println("Invalid option");
  65.         }
  66.     }
  67.    
  68.     //Return a book
  69.     private static void returnBook(){
  70.         System.out.println("Would you like to return a book? (1 yes or 2 no)");
  71.         int in = input.nextInt();
  72.         if(in == 1){
  73.             //Return a book
  74.             System.out.println("Which book would you like to return?");
  75.             String bookReturn = input.nextLine();
  76.             if(customer.returnBook(bookReturn)){
  77.                 System.out.println(bookReturn + " has been returned");
  78.             } else {
  79.                 System.out.println("Sorry, could not find the book " + bookReturn);
  80.             }
  81.         } else if((in != 1) || (in != 2)){
  82.             System.out.println("Invalid option");
  83.         }
  84.     }
  85.    
  86.     //See if a book is taken out
  87.     private static void checkBook(){
  88.         //See if book is taken out
  89.         System.out.println("Which book would you like to check for?");
  90.         String thisBook = input.nextLine();
  91.         if(customer.checkForBook(thisBook)){
  92.             System.out.println("The patron has taken out the book " + thisBook);
  93.         } else {
  94.             System.out.println("The patron does not have " + thisBook + " taken out");
  95.         }
  96.     }
  97.    
  98.     //Print the list of taken out books
  99.     private static String printBooks(){
  100.         String output = "Books taken out: \n";
  101.         output += b1.toString() + "\n";
  102.         output += b2.toString() + "\n";
  103.         output += b3.toString() + "\n";
  104.        
  105.         return output;
  106.     }
  107.    
  108.    
  109.     /**             **/
  110.     /** MAIN METHOD **/
  111.     /**             **/
  112.     public static void main(String[] args){
  113.        
  114.         //Get information of initial 3 books, 3 books are required
  115.         getInformation();
  116.        
  117.         //Do this cycle 5 times
  118.         for(int i = 0; i <= 5; i++){
  119.             checkBook();
  120.             returnBook();
  121.             takeOutBook();
  122.             printBooks();
  123.         }
  124.     }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement