Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Client {
- //Used for all input
- public static Scanner input = new Scanner(System.in);
- //3 Book objects
- public static Book b1, b2, b3;
- //String variables for the title and author of each book
- public static String b1Title, b1Author;
- public static String b2Title, b2Author;
- public static String b3Title, b3Author;
- //Patron object
- public static Patron customer;
- //Get initial book information
- private static void getInformation(){
- //Book 1 information
- System.out.println("Please enter title of book 1: ");
- b1Title = input.nextLine();
- System.out.println("Please enter author of book 1: ");
- b1Author = input.nextLine();
- b1 = new Book(b1Title, b1Author);
- //Book 2 information
- System.out.println("Please enter title of book 2: ");
- b2Title = input.nextLine();
- System.out.println("Please enter author of book 2:");
- b2Author = input.nextLine();
- b2 = new Book(b2Title, b2Author);
- //Book 3 information
- System.out.println("Please enter title of book 3: ");
- b3Title = input.nextLine();
- System.out.println("Please enter author of book 3:");
- b3Author = input.nextLine();
- b3 = new Book(b3Title, b3Author);
- //Initialize the patron object
- customer = new Patron(b1, b2, b3);
- }
- //Take out a book
- private static void takeOutBook(){
- //Book info of book to take out
- System.out.println("Would you like to take out a book? (1 yes or 2 no)");
- int in = input.nextInt();
- if(in == 1) {
- System.out.println("Name of book to take out: ");
- String bookTitle = input.nextLine();
- System.out.println("Author of book to take out: ");
- String bookAuthor = input.nextLine();
- //Check for open slots
- if(customer.takeOut(bookTitle, bookAuthor)){
- System.out.println("The book " + bookTitle + " has been taken out");
- } else {
- System.out.println("You must return a book before taking out another!");
- }
- } else if((in != 1) || (in!= 2)){
- System.out.println("Invalid option");
- }
- }
- //Return a book
- private static void returnBook(){
- System.out.println("Would you like to return a book? (1 yes or 2 no)");
- int in = input.nextInt();
- if(in == 1){
- //Return a book
- System.out.println("Which book would you like to return?");
- String bookReturn = input.nextLine();
- if(customer.returnBook(bookReturn)){
- System.out.println(bookReturn + " has been returned");
- } else {
- System.out.println("Sorry, could not find the book " + bookReturn);
- }
- } else if((in != 1) || (in != 2)){
- System.out.println("Invalid option");
- }
- }
- //See if a book is taken out
- private static void checkBook(){
- //See if book is taken out
- System.out.println("Which book would you like to check for?");
- String thisBook = input.nextLine();
- if(customer.checkForBook(thisBook)){
- System.out.println("The patron has taken out the book " + thisBook);
- } else {
- System.out.println("The patron does not have " + thisBook + " taken out");
- }
- }
- //Print the list of taken out books
- private static String printBooks(){
- String output = "Books taken out: \n";
- output += b1.toString() + "\n";
- output += b2.toString() + "\n";
- output += b3.toString() + "\n";
- return output;
- }
- /** **/
- /** MAIN METHOD **/
- /** **/
- public static void main(String[] args){
- //Get information of initial 3 books, 3 books are required
- getInformation();
- //Do this cycle 5 times
- for(int i = 0; i <= 5; i++){
- checkBook();
- returnBook();
- takeOutBook();
- printBooks();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement