Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package chapter07;
- import javax.swing.JOptionPane;
- public class Book {//begin class
- /**
- * @param args
- */
- //public variables
- static String[][] book = new String[4][4];
- static String[][] patron = new String [3][4];
- public static void main(String[] args) {//begin main
- //variables
- InputBox input = new InputBox();
- BookMethods methods = new BookMethods();
- String bookName = null;
- String patronId = null;
- String message = null;
- String title = null;
- int type = 0;
- int bookIndex = 999;
- int patronIndex = 999;
- int again = 0;
- //array for option box
- String[] choices = {"Yes", "No"};
- //load and print arrays
- book = methods.loadBookArray(book);
- patron = methods.loadPatronArray(patron);
- //print arrays
- methods.printBook(book);
- System.out.println();
- methods.printPatron(patron);
- do {//begin do
- //get book name
- message = "Please enter the name of the book you'd like to check out, or type quit to exit.";
- title = "Book";
- type = 3;
- bookName = input.getString(message, title, type);
- if (bookName.equalsIgnoreCase("quit")){//if quit
- System.out.println("Thank you for your patronage. Have a nice day!");
- System.exit(0);
- }//end if quit
- else {//begin else
- bookIndex = methods.findBookMatch(book,bookName);
- System.out.println(bookIndex);
- }//end else
- do{//begin error
- JOptionPane.showMessageDialog(null,"Error! That is not a valid entry.\nPlease try again.","Error", JOptionPane.ERROR_MESSAGE);
- bookName = input.getString(message, title, type);
- if (bookName.equalsIgnoreCase("quit")){//if quit error
- System.out.println("Thank you for your patronage. Have a nice day!");
- System.exit(0);
- }//end if quit error
- bookIndex = methods.findBookMatch(book,bookName);
- }//end error
- while (bookIndex == 999);
- //patron ID
- message = "Please enter your patron ID, or type quit to exit.";
- title = "Patron ID";
- type = 3;
- patronId = input.getString(message, title, type);
- if (patronId.equalsIgnoreCase("quit")){//if quit
- System.out.println("Thank you for your patronage. Have a nice day!");
- System.exit(0);
- }//end if quit
- else {//begin else
- patronIndex = methods.findPatronMatch(patron,patronId);
- }//end else
- do {//begin error
- JOptionPane.showMessageDialog(null,"Error! That is not a valid entry.\nPlease try again.","Error", JOptionPane.ERROR_MESSAGE);
- patronId = input.getString(message, title, type);
- if (patronId.equalsIgnoreCase("quit")){//if quit error
- System.out.println("Thank you for your patronage. Have a nice day!");
- System.exit(0);
- }//end if quit error
- patronIndex = methods.findBookMatch(book,bookName);
- }//end error
- while (patronIndex == 999);
- book[bookIndex][3] = patronId;
- System.out.println("The book " + book[bookIndex][0] + " has been checked out by patron #" + patronId + ", " + patron[patronIndex][0]);
- again = JOptionPane.showOptionDialog(
- null
- , "Would you like to check out another book?" // Message
- , "Another Book?" // Title in titlebar
- , JOptionPane.YES_NO_OPTION // Option type
- , JOptionPane.PLAIN_MESSAGE // messageType
- , null // Icon (none)
- , choices // Button text as above
- , "Yes" // Default button's label
- );
- }//end do
- while (again == 0);
- //print new book data
- methods.printBook(book);
- System.exit(0);
- }//end main
- }//end class
Add Comment
Please, Sign In to add comment