Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class StamatCookbook {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- Map<String, ArrayList<String>> cookbook = new TreeMap<>();
- String input = scanner.nextLine();
- while (!"cook".equalsIgnoreCase (input)) {
- String recipeNameOrCommand = input.substring(0, input.indexOf("->"));
- if ("Remove".equalsIgnoreCase (recipeNameOrCommand)) {
- String[] tokens = input.substring(input.indexOf(">") + 1).split(", ");
- String recipeName = tokens[0];
- String ingredient = tokens[1];
- if (!cookbook.containsKey(recipeName)) {
- System.out.println(String.format("%s does not exist!", recipeName));
- } else {
- ArrayList<String> curr = cookbook.get(recipeName);
- if (curr.contains(ingredient)) {
- curr.remove(ingredient);
- }
- }
- } else if ("change".equalsIgnoreCase (recipeNameOrCommand)) {
- String[] tokens = input.substring(input.indexOf(">") + 1).split(", ");
- String recipeName = tokens[0];
- String ingredient1 = tokens[1];
- String ingredient2 = tokens[2];
- if (!cookbook.containsKey(recipeName)) {
- System.out.println(String.format("Can't change %s!", ingredient2));
- } else {
- ArrayList<String> curr = cookbook.get(recipeName);
- if (curr.contains(ingredient1)) {
- int index = curr.indexOf(ingredient1);
- curr.remove(ingredient1);
- curr.add(index, ingredient2);
- System.out.println(String.format("%s was replaced by %s at %dth position.", ingredient1, ingredient2, index));
- } else {
- curr.add(ingredient2);
- System.out.println(String.format("You just add %s to the %s recipe.", ingredient2, recipeName));
- }
- }
- } else {
- String[] tokens = input.substring(input.indexOf(">") + 1).split(">>>");
- if (!cookbook.containsKey(recipeNameOrCommand)) {
- ArrayList<String> curr = new ArrayList<>();
- curr.addAll(Arrays.asList(tokens));
- cookbook.put(recipeNameOrCommand, curr);
- }
- }
- input = scanner.nextLine();
- }
- String recipeForCook = scanner.nextLine();
- System.out.println(String.format("Easy %s:", recipeForCook));
- ArrayList<String> curr = cookbook.get(recipeForCook);
- Collections.sort(curr);
- for (String ingredient : curr) {
- System.out.println("* " + ingredient);
- }
- System.out.println(String.format("Stamat's cookbook contains %d recipes:", cookbook.size()));
- for (String s : cookbook.keySet()) {
- System.out.println("* " + s);
- }
- }
- }
- /*
- hummus->tahini - 80 ml.>>>cold water - 4 tbs.>>>olive oil - 2 tbs.>>>ground cumin - 1 tsp.>>>salt - 1 tsp.>>>cloves garlic - 2>>>lemon juice – 3 tsp.>>>chickpeas - 425 gr.
- beef wellington->beef tenderloin - 450 gr.>>>olive oil – 2 tbs.>>>mushrooms - 450 gr.>>>slices ham - 3>>>yellow mustard - 2 tbs.>>>puff pastry – 200 gr.>>>egg yolks - 2>>>salt - 4 gr.>>>black pepper - 2 gr.>>>chocolate – 60 gr.
- spaghetti carbonara->pancetta - 100 gr.>>>large eggs - 2>>>pecorino cheese - 50 g.>>>parmesan - 50 gr.>>>spaghetti - 350 gr.>>>garlic cloves - 2>>>butter - 50 gr.>>>salt - 5 gr.>>>black pepper - 3 gr.
- banica->feta cheese - 300 gr.>>>large eggs - 4>>>yogurt - 100 g.>>>backing soda - 5 gr.>>>pastry - 400 gr. >>>pork shoulder - 500 gr.
- Change->musaka, banana - 2, carrots - 150 gr.
- Remove->beef wellington, chocolate – 60 gr.
- change->banica, pork shoulder - 500 gr., butter - 50 gr.
- cook
- banica
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement