Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class BookUI {
- public static int getMenuChoice(Scanner keyboard) {
- int choice;
- do{
- System.out.println("--------------"+ "\n Menu"+ "\n--------------"+"\n1. Add a new book"+"\n2. Display all books"+"\n3. Display the cheapest book"+"\n4. Quit"+"\nEnter Your Choice ( 1 / 2 / 3 / 4 ):");
- choice=keyboard.nextInt();
- }while(choice==0 || choice>4);
- return choice;
- }
- public static void displayBook(Book book) {
- System.out.println(book.isbn+":"+ book.title+":" + book.author+":"+ book.price+" \n");
- }
- public static void displayBooks(Book[] books) {
- for(int i=0;i<books.length;i++){
- if(books[i]!=null){
- displayBook(books[i]);
- }
- }
- }
- public static Book readBook(Scanner keyboard) {
- Book returned = new Book();
- System.out.println("Enter the following attributes for your book:\n" + "Enter the isbn:\n");
- String isbn=keyboard.nextLine();
- System.out.println("Enter the title:");
- String title = keyboard.nextLine();
- System.out.println("Enter the author's name:");
- String author=keyboard.nextLine();
- System.out.println("Enter the price of the book:");
- double price=keyboard.nextDouble();
- returned.isbn=isbn;
- returned.title=title;
- returned.author=author;
- returned.price=price;
- return returned;
- }
- }
Add Comment
Please, Sign In to add comment