Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Emma Weil
- Segall
- AP Computer Science pd. 8
- 9/23/11
- This is a program to creates the Library class that will serve as an interface for the Book/Patron classes.
- */
- import TerminalIO.KeyboardReader;
- public class Library{
- public static void main(String [] args){
- KeyboardReader reader = new KeyboardReader();
- Patron p1 = new Patron("Joshua"); /// This one is Bob because I don't really like the name Bob
- Patron p2 = new Patron("Alec"); /// This one is Jim because I don't really like the name Jim, either
- String title = "";
- String author = "";
- String name = "";
- int ans = 0;
- while(true)
- {
- name = reader.readLine("What is your name, patron? ('no one' to quit) ");
- if (name.equals("no one"))
- {
- break;
- }
- while (name.equals("Joshua"))
- {
- ans = reader.readInt("Would you like to check out a book? (1 for yes, 0 for no) ");
- if (ans!=1)
- {
- break;
- }
- title = reader.readLine("What is the title of the book you would like to check out? ");
- author = reader.readLine("What is the author of the book you would like to check out? ");
- System.out.println();
- while ( p1.borrowBook(title, author) == false)
- {
- System.out.println("You cannot borrow any more books. Please return a book first.");
- System.out.println("\nThe books you have checked out currently are: \n" + p1);
- title = reader.readLine("What is the title of the book you would like to return? ");
- while (p1.hasBook(title) == false)
- {
- System.out.println("You haven't checked that book out, so you can't return it. ");
- 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) ");
- if (title.equals("none"))
- {
- break;
- }
- }
- p1.returnBook(title);
- System.out.println("Okay, you have room to borrow another book. ");
- title = reader.readLine("What is the title of the book you would like to check out? ");
- author = reader.readLine("What is the author of the book you would like to check out? ");
- System.out.println();
- }
- }
- if (name.equals("Joshua"))
- {
- System.out.println();
- System.out.println("Goodbye, " + name);
- }
- while (name.equals("Alec"))
- {
- ans = reader.readInt("Would you like to check out a book? (1 for yes, 0 for no) ");
- if (ans!=1)
- {
- break;
- }
- title = reader.readLine("What is the title of the book you would like to check out? ");
- author = reader.readLine("What is the author of the book you would like to check out? ");
- System.out.println();
- while ( p2.borrowBook(title, author) == false)
- {
- System.out.println("You cannot borrow any more books. Please return a book first.");
- System.out.println("\nThe books you have checked out currently are: \n" + p2);
- title = reader.readLine("What is the title of the book you would like to return? ");
- while (p2.hasBook(title) == false)
- {
- System.out.println("You haven't checked that book out, so you can't return it. ");
- 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) ");
- if (title.equals("none"))
- {
- break;
- }
- }
- p2.returnBook(title);
- System.out.println("Okay, you have room to borrow another book. ");
- title = reader.readLine("What is the title of the book you would like to check out? ");
- author = reader.readLine("What is the author of the book you would like to check out? ");
- System.out.println();
- }
- }
- if (name.equals("Alec"))
- {
- System.out.println();
- System.out.println("Goodbye, " + name);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment