Advertisement
Guest User

Untitled

a guest
Nov 10th, 2019
466
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. import java.util.Map;
  2. import java.util.Scanner;
  3. import java.util.TreeMap;
  4.  
  5. public class E03_LegendaryFarming {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8. Map<String, Integer> specialItems = new TreeMap<>();
  9. Map<String, Integer> junkItems = new TreeMap<>();
  10.  
  11. boolean isObtained = false;
  12. specialItems.put("shards", 0);
  13. specialItems.put("fragments", 0);
  14. specialItems.put("motes", 0);
  15.  
  16. while (!isObtained) {
  17. int quantity = Integer.parseInt(scanner.next());
  18. String item = scanner.next().toLowerCase();
  19.  
  20. switch (item) {
  21. case "shards":
  22. if (!specialItems.containsKey(item)) {
  23. specialItems.putIfAbsent(item, quantity);
  24. } else {
  25. specialItems.put(item, specialItems.get(item) + quantity);
  26. }
  27. if (specialItems.get(item) >= 250) {
  28. System.out.println("Shadowmourne Obtained!");
  29. specialItems.put(item, specialItems.get(item) - 250);
  30. isObtained = true;
  31. }
  32.  
  33. break;
  34. case "fragments":
  35. if (!specialItems.containsKey(item)) {
  36. specialItems.putIfAbsent(item, quantity);
  37. } else {
  38. specialItems.put(item, specialItems.get(item) + quantity);
  39. }
  40. if (specialItems.get(item) >= 250) {
  41. System.out.println("Valanyr obtained!");
  42. isObtained = true;
  43. specialItems.put(item, specialItems.get(item) - 250);
  44. }
  45.  
  46. break;
  47. case "motes":
  48. if (!specialItems.containsKey(item)) {
  49. specialItems.putIfAbsent(item, quantity);
  50. } else {
  51. specialItems.put(item, specialItems.get(item) + quantity);
  52. }
  53. if (specialItems.get(item) >= 250) {
  54. System.out.println("Dragonwrath obtained!");
  55. isObtained = true;
  56. specialItems.put(item, specialItems.get(item) - 250);
  57. }
  58.  
  59. break;
  60. default:
  61. if (!junkItems.containsKey(item)) {
  62. junkItems.putIfAbsent(item, quantity);
  63. } else {
  64. junkItems.put(item, junkItems.get(item) + quantity);
  65. }
  66. }
  67. }
  68.  
  69. specialItems.entrySet().stream().sorted((a, b) -> b.getValue().compareTo(a.getValue()))
  70. .forEach((entry) -> System.out.println(entry.getKey() + ": " + entry.getValue()));
  71. junkItems.forEach((k, v) -> System.out.println(k + ": " + v));
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement