Guest User

Untitled

a guest
Apr 20th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.64 KB | None | 0 0
  1. package chapter07;
  2.  
  3. import javax.swing.JOptionPane;
  4.  
  5. public class Book {//begin class
  6.  
  7.     /**
  8.      * @param args
  9.      */
  10.     //public variables
  11.     static String[][] book = new String[4][4];
  12.     static String[][] patron = new String [3][4];
  13.    
  14.     public static void main(String[] args) {//begin main
  15.  
  16.         //variables
  17.         InputBox input = new InputBox();
  18.         BookMethods methods = new BookMethods();
  19.         String bookName = null;
  20.         String patronId = null;
  21.         String message = null;
  22.         String title = null;
  23.         int type = 0;
  24.         int bookIndex = 999;
  25.         int patronIndex = 999;
  26.         int again = 0;
  27.        
  28.         //array for option box
  29.         String[] choices = {"Yes", "No"};
  30.        
  31.        
  32.         //load and print arrays
  33.         book = methods.loadBookArray(book);
  34.         patron = methods.loadPatronArray(patron);
  35.        
  36.         //print arrays
  37.         methods.printBook(book);
  38.         System.out.println();
  39.         methods.printPatron(patron);
  40.  
  41.         do {//begin do
  42.            
  43.             //get book name
  44.             message = "Please enter the name of the book you'd like to check out, or type quit to exit.";
  45.             title = "Book";
  46.             type = 3;
  47.             bookName = input.getString(message, title, type);
  48.             if (bookName.equalsIgnoreCase("quit")){//if quit
  49.                 System.out.println("Thank you for your patronage. Have a nice day!");
  50.                 System.exit(0);
  51.             }//end if quit
  52.             else {//begin else
  53.                 bookIndex = methods.findBookMatch(book,bookName);
  54.                 System.out.println(bookIndex);
  55.             }//end else
  56.             do{//begin error
  57.                 JOptionPane.showMessageDialog(null,"Error! That is not a valid entry.\nPlease try again.","Error", JOptionPane.ERROR_MESSAGE);
  58.                 bookName = input.getString(message, title, type);
  59.                 if (bookName.equalsIgnoreCase("quit")){//if quit error
  60.                     System.out.println("Thank you for your patronage. Have a nice day!");
  61.                     System.exit(0);
  62.                 }//end if quit error
  63.                     bookIndex = methods.findBookMatch(book,bookName);
  64.             }//end error
  65.             while (bookIndex == 999);
  66.                
  67.             //patron ID
  68.             message = "Please enter your patron ID, or type quit to exit.";
  69.             title = "Patron ID";
  70.             type = 3;
  71.             patronId = input.getString(message, title, type);
  72.             if (patronId.equalsIgnoreCase("quit")){//if quit
  73.                 System.out.println("Thank you for your patronage. Have a nice day!");
  74.                 System.exit(0);
  75.             }//end if quit
  76.             else {//begin else
  77.                 patronIndex = methods.findPatronMatch(patron,patronId);
  78.             }//end else
  79.             do {//begin error
  80.                 JOptionPane.showMessageDialog(null,"Error! That is not a valid entry.\nPlease try again.","Error", JOptionPane.ERROR_MESSAGE);
  81.                 patronId = input.getString(message, title, type);
  82.                 if (patronId.equalsIgnoreCase("quit")){//if quit error
  83.                     System.out.println("Thank you for your patronage. Have a nice day!");
  84.                     System.exit(0);
  85.                 }//end if quit error
  86.                     patronIndex = methods.findBookMatch(book,bookName);
  87.             }//end error
  88.             while (patronIndex == 999);
  89.            
  90.             book[bookIndex][3] =  patronId;
  91.             System.out.println("The book " + book[bookIndex][0] + " has been checked out by patron #" + patronId + ", " + patron[patronIndex][0]);
  92.            
  93.             again = JOptionPane.showOptionDialog(
  94.                     null                  
  95.                   , "Would you like to check out another book?"             // Message
  96.                   , "Another Book?"                     // Title in titlebar
  97.                   , JOptionPane.YES_NO_OPTION   // Option type
  98.                   , JOptionPane.PLAIN_MESSAGE   // messageType
  99.                   , null                        // Icon (none)
  100.                   , choices                     // Button text as above
  101.                   , "Yes"                   // Default button's label
  102.                 );
  103.            
  104.            
  105.            
  106.         }//end do
  107.         while (again == 0);
  108.        
  109.        
  110.        
  111.         //print new book data
  112.         methods.printBook(book);
  113.        
  114.        
  115.        
  116.        
  117.        
  118.        
  119.         System.exit(0);
  120.     }//end main
  121.        
  122. }//end class
Add Comment
Please, Sign In to add comment