Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class StamatCookbook {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. Map<String, ArrayList<String>> cookbook = new TreeMap<>();
  8.  
  9. String input = scanner.nextLine();
  10.  
  11. while (!"cook".equalsIgnoreCase (input)) {
  12. String recipeNameOrCommand = input.substring(0, input.indexOf("->"));
  13.  
  14. if ("Remove".equalsIgnoreCase (recipeNameOrCommand)) {
  15.  
  16. String[] tokens = input.substring(input.indexOf(">") + 1).split(", ");
  17. String recipeName = tokens[0];
  18. String ingredient = tokens[1];
  19. if (!cookbook.containsKey(recipeName)) {
  20. System.out.println(String.format("%s does not exist!", recipeName));
  21. } else {
  22. ArrayList<String> curr = cookbook.get(recipeName);
  23. if (curr.contains(ingredient)) {
  24. curr.remove(ingredient);
  25. }
  26. }
  27.  
  28. } else if ("change".equalsIgnoreCase (recipeNameOrCommand)) {
  29.  
  30. String[] tokens = input.substring(input.indexOf(">") + 1).split(", ");
  31. String recipeName = tokens[0];
  32. String ingredient1 = tokens[1];
  33. String ingredient2 = tokens[2];
  34. if (!cookbook.containsKey(recipeName)) {
  35. System.out.println(String.format("Can't change %s!", ingredient2));
  36. } else {
  37. ArrayList<String> curr = cookbook.get(recipeName);
  38. if (curr.contains(ingredient1)) {
  39. int index = curr.indexOf(ingredient1);
  40. curr.remove(ingredient1);
  41. curr.add(index, ingredient2);
  42. System.out.println(String.format("%s was replaced by %s at %dth position.", ingredient1, ingredient2, index));
  43. } else {
  44. curr.add(ingredient2);
  45. System.out.println(String.format("You just add %s to the %s recipe.", ingredient2, recipeName));
  46. }
  47. }
  48.  
  49. } else {
  50.  
  51. String[] tokens = input.substring(input.indexOf(">") + 1).split(">>>");
  52. if (!cookbook.containsKey(recipeNameOrCommand)) {
  53. ArrayList<String> curr = new ArrayList<>();
  54. curr.addAll(Arrays.asList(tokens));
  55. cookbook.put(recipeNameOrCommand, curr);
  56. }
  57.  
  58. }
  59.  
  60.  
  61. input = scanner.nextLine();
  62. }
  63.  
  64. String recipeForCook = scanner.nextLine();
  65.  
  66. System.out.println(String.format("Easy %s:", recipeForCook));
  67. ArrayList<String> curr = cookbook.get(recipeForCook);
  68. Collections.sort(curr);
  69. for (String ingredient : curr) {
  70. System.out.println("* " + ingredient);
  71. }
  72.  
  73. System.out.println(String.format("Stamat's cookbook contains %d recipes:", cookbook.size()));
  74.  
  75. for (String s : cookbook.keySet()) {
  76. System.out.println("* " + s);
  77. }
  78.  
  79. }
  80. }
  81. /*
  82. 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.
  83. 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.
  84. 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.
  85. banica->feta cheese - 300 gr.>>>large eggs - 4>>>yogurt - 100 g.>>>backing soda - 5 gr.>>>pastry - 400 gr. >>>pork shoulder - 500 gr.
  86. Change->musaka, banana - 2, carrots - 150 gr.
  87. Remove->beef wellington, chocolate – 60 gr.
  88. change->banica, pork shoulder - 500 gr., butter - 50 gr.
  89. cook
  90. banica
  91. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement