Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Interface {
- private Scanner scan;
- private RecipeBook book;
- public Interface(Scanner scan,RecipeBook book){
- this.scan=scan;
- this.book=book;
- }
- public void Start(){
- boolean loop=true;
- System.out.println("Commands:\n"
- + "list - lists the recipes\n"
- + "stop - stops the program\n"
- + "find name - searches recipes by name\n"
- + "find cooking time - searches recipes by cooking time\n"
- + "find ingredient - searches recipes by ingredient");
- System.out.println("");
- while(loop){
- System.out.print("Enter command: ");
- String command=scan.nextLine();
- switch(command){
- case "stop":
- loop=false;
- break;
- case "list":
- System.out.println("Recipes:");
- this.book.printRecipe();
- break;
- case "find name":
- System.out.print("Searched word: ");
- String searched=scan.nextLine();
- System.out.println("Recipes:");
- this.book.printByName(searched);
- break;
- case "find cooking time":
- System.out.print("Max cooking time: ");
- int maxTime=Integer.parseInt(scan.nextLine());
- System.out.println("Recipes:");
- this.book.printByTime(maxTime);
- break;
- case "find ingredient":
- System.out.print("Ingredient: ");
- String ingredient=scan.nextLine();
- System.out.println("Recipes:");
- this.book.printByIngredient(ingredient);
- break;
- default:
- System.out.println("Unknow comand");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement