Advertisement
irishstorm

Bookstore.java

Jan 15th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.95 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class BookStore
  4. {
  5.     public static void main(String[] args)
  6.     {
  7.         Scanner input = new Scanner(System.in);
  8.         ArrayList<Book> bookList = new ArrayList();
  9.         Boolean isPopulated = false;
  10.         int option = 0;
  11.  
  12.         do
  13.         {
  14.             MainMemu();
  15.             option = input.nextInt();
  16.  
  17.             switch(option)
  18.             {
  19.                 case 1:
  20.                     generateBookList(bookList);
  21.                     isPopulated = true;
  22.                     break;
  23.  
  24.                 case 2:
  25.                     if(isPopulated)
  26.                         getBookList(bookList);
  27.                     else
  28.                         System.out.println("Sorry, The Booklist hasn't been generated, please try option 1.");
  29.                     break;
  30.  
  31.                 case 3:
  32.                     System.exit(0);
  33.                     break;
  34.  
  35.                 default:
  36.                     System.out.print("Error: Invailed option, please select another.");
  37.             }
  38.         }
  39.         while(option != 100000);
  40.     }
  41.  
  42.     public static void MainMemu()
  43.     {
  44.         System.out.println("1.\tGenerate Book List\n2.\tDisplay booklist\n3.\tExit");
  45.     }
  46.  
  47.     public static void getBookList(ArrayList<Book> bookList)
  48.     {
  49.         Book getBookObject = new Book("");
  50.  
  51.         for(int x = 0; x < bookList.size(); x++)
  52.         {
  53.             getBookObject = bookList.get(x);
  54.  
  55.             System.out.println(getBookObject.getTitle());
  56.         }
  57.     }
  58.    
  59.     public static void generateBookList(ArrayList<Book> bookList)
  60.     {
  61.         System.out.println("Starting book generation...");
  62.  
  63.         for (int i = 0; i < 5; i++)
  64.         {
  65.             Book newBookObject = new Book("Book title " + ( i + 1 ));
  66.             bookList.add(newBookObject);
  67.             System.out.println("Book " + i + " out of 5 has been generated");
  68.         }
  69.  
  70.         System.out.println("Book list generated.");
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement