Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class BookStore
- {
- public static void main(String[] args)
- {
- Scanner input = new Scanner(System.in);
- ArrayList<Book> bookList = new ArrayList();
- Boolean isPopulated = false;
- int option = 0;
- do
- {
- MainMemu();
- option = input.nextInt();
- switch(option)
- {
- case 1:
- generateBookList(bookList);
- isPopulated = true;
- break;
- case 2:
- if(isPopulated)
- getBookList(bookList);
- else
- System.out.println("Sorry, The Booklist hasn't been generated, please try option 1.");
- break;
- case 3:
- System.exit(0);
- break;
- default:
- System.out.print("Error: Invailed option, please select another.");
- }
- }
- while(option != 100000);
- }
- public static void MainMemu()
- {
- System.out.println("1.\tGenerate Book List\n2.\tDisplay booklist\n3.\tExit");
- }
- public static void getBookList(ArrayList<Book> bookList)
- {
- Book getBookObject = new Book("");
- for(int x = 0; x < bookList.size(); x++)
- {
- getBookObject = bookList.get(x);
- System.out.println(getBookObject.getTitle());
- }
- }
- public static void generateBookList(ArrayList<Book> bookList)
- {
- System.out.println("Starting book generation...");
- for (int i = 0; i < 5; i++)
- {
- Book newBookObject = new Book("Book title " + ( i + 1 ));
- bookList.add(newBookObject);
- System.out.println("Book " + i + " out of 5 has been generated");
- }
- System.out.println("Book list generated.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement