Advertisement
Guest User

Untitled

a guest
Jul 18th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1.  
  2. import java.util.*;
  3.  
  4. public class treasureHunt {
  5. public static void main(String[] args) {
  6. Scanner sc = new Scanner(System.in);
  7.  
  8. int unLiked = 0;
  9. TreeMap<String, List<String>> listMap = new TreeMap<>();
  10.  
  11. List<String> dishes = new ArrayList<>();
  12.  
  13.  
  14.  
  15. String input = sc.nextLine();
  16.  
  17. while (!"Stop".equals(input)){
  18. String[] token = input.split("-");
  19. String likeUnlike = token[0];
  20. String name = token[1];
  21. String dish = token[2];
  22.  
  23. if (likeUnlike.equals("Like")){
  24.  
  25. if (listMap.containsKey(name)){
  26. if (!listMap.get(name).contains(dish)){
  27. listMap.get(name).add(dish);
  28. }
  29. }else {
  30. dishes=new ArrayList<>();
  31. dishes.add(dish);
  32. listMap.put(name,dishes);
  33. }
  34.  
  35. }else if (likeUnlike.equals("Unlike")){
  36. if (!listMap.containsKey(name)){
  37. System.out.printf("%s is not at the party.%n",name);
  38. } else if (!listMap.get(name).contains(dish)){
  39. System.out.printf("%s doesn't have the %s in his/her collection.%n", name,dish);
  40. }else {
  41. unLiked++;
  42. listMap.get(name).remove(dish);
  43. System.out.printf("%s doesn't like the %s.%n",name,dish);
  44.  
  45. }
  46. }
  47.  
  48.  
  49. input= sc.nextLine();
  50. }
  51.  
  52. for (Map.Entry<String, List<String>> stringListEntry : listMap.entrySet()) {
  53. System.out.print(stringListEntry.getKey() + ": ");
  54. System.out.println(String.join(", ",stringListEntry.getValue()));
  55. }
  56. System.out.printf("Unliked meals: %d", unLiked);
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement