Guest User

Untitled

a guest
Jul 17th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4.  
  5. public class BookUI {
  6.  
  7. public static int getMenuChoice(Scanner keyboard) {
  8. int choice;
  9. do{
  10. 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 ):");
  11. choice=keyboard.nextInt();
  12. }while(choice==0 || choice>4);
  13. return choice;
  14.  
  15. }
  16.  
  17.  
  18. public static void displayBook(Book book) {
  19. System.out.println(book.isbn+":"+ book.title+":" + book.author+":"+ book.price+" \n");
  20. }
  21.  
  22.  
  23. public static void displayBooks(Book[] books) {
  24. for(int i=0;i<books.length;i++){
  25. if(books[i]!=null){
  26. displayBook(books[i]);
  27. }
  28. }
  29. }
  30.  
  31. public static Book readBook(Scanner keyboard) {
  32.  
  33.  
  34. Book returned = new Book();
  35.  
  36. System.out.println("Enter the following attributes for your book:\n" + "Enter the isbn:\n");
  37. String isbn=keyboard.nextLine();
  38. System.out.println("Enter the title:");
  39. String title = keyboard.nextLine();
  40. System.out.println("Enter the author's name:");
  41. String author=keyboard.nextLine();
  42. System.out.println("Enter the price of the book:");
  43. double price=keyboard.nextDouble();
  44.  
  45. returned.isbn=isbn;
  46. returned.title=title;
  47. returned.author=author;
  48. returned.price=price;
  49.  
  50. return returned;
  51.  
  52. }
  53.  
  54. }
Add Comment
Please, Sign In to add comment