Advertisement
Guest User

Untitled

a guest
Dec 5th, 2024
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | Source Code | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4.  
  5. public class Interface {
  6. private Scanner scan;
  7. private RecipeBook book;
  8.  
  9. public Interface(Scanner scan,RecipeBook book){
  10. this.scan=scan;
  11. this.book=book;
  12.  
  13. }
  14.  
  15. public void Start(){
  16. boolean loop=true;
  17. System.out.println("Commands:\n"
  18. + "list - lists the recipes\n"
  19. + "stop - stops the program\n"
  20. + "find name - searches recipes by name\n"
  21. + "find cooking time - searches recipes by cooking time\n"
  22. + "find ingredient - searches recipes by ingredient");
  23. System.out.println("");
  24.  
  25. while(loop){
  26.  
  27. System.out.print("Enter command: ");
  28. String command=scan.nextLine();
  29.  
  30.  
  31. switch(command){
  32.  
  33. case "stop":
  34. loop=false;
  35. break;
  36. case "list":
  37. System.out.println("Recipes:");
  38. this.book.printRecipe();
  39. break;
  40. case "find name":
  41. System.out.print("Searched word: ");
  42. String searched=scan.nextLine();
  43. System.out.println("Recipes:");
  44. this.book.printByName(searched);
  45. break;
  46. case "find cooking time":
  47. System.out.print("Max cooking time: ");
  48. int maxTime=Integer.parseInt(scan.nextLine());
  49. System.out.println("Recipes:");
  50. this.book.printByTime(maxTime);
  51. break;
  52. case "find ingredient":
  53. System.out.print("Ingredient: ");
  54. String ingredient=scan.nextLine();
  55. System.out.println("Recipes:");
  56. this.book.printByIngredient(ingredient);
  57. break;
  58. default:
  59. System.out.println("Unknow comand");
  60. }
  61. }
  62. }
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement