IvaAnd

Ex03_LegendaryFarming

Jul 15th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. import java.util.Map;
  2. import java.util.Scanner;
  3. import java.util.TreeMap;
  4.  
  5. public class Ex03_LegendaryFarming {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. Map<String, Integer> farming = new TreeMap<>();
  10. Map<String, Integer> junk = new TreeMap<>();
  11.  
  12. farming.put("shards", 0);
  13. farming.put("fragments", 0);
  14. farming.put("motes", 0);
  15.  
  16. boolean legenderyReached = false;
  17. while (!legenderyReached) {
  18. String[] input = scanner.nextLine().split(" ");
  19.  
  20. for (int i = 0; i < input.length; i = i + 2) {
  21. int quantity = Integer.parseInt(input[i]);
  22. String material = input[i + 1].toLowerCase();
  23. int sum = 0;
  24.  
  25. if (farming.containsKey(material)) {
  26. sum = farming.get(material) + quantity;
  27. farming.put(material, sum);
  28. } else {
  29. if (!junk.containsKey(material)) {
  30. junk.put(material, quantity);
  31. } else {
  32. sum = junk.get(material) + quantity;
  33. junk.put(material, sum);
  34. }
  35.  
  36. }
  37. if (farming.get("shards") >= 250
  38. || farming.get("fragments") >= 250
  39. || farming.get("motes") >= 250) {
  40.  
  41. if (material.equals("shards")) {
  42. System.out.println("Shadowmourne obtained!");
  43. } else if (material.equals("fragments")) {
  44. System.out.println("Valanyr obtained!");
  45. } else {
  46. System.out.println("Dragonwrath obtained!");
  47. }
  48. int finalQuantity = farming.get(material) - 250;
  49. farming.put(material, finalQuantity);
  50. legenderyReached = true;
  51. break;
  52. }
  53.  
  54. }
  55.  
  56. }
  57. farming.entrySet().stream().sorted((f, s) -> {
  58. int result = s.getValue().compareTo(f.getValue());
  59. if (result == 0) {
  60. result = f.getKey().compareTo(s.getKey());
  61. }
  62. return result;
  63. }).forEach(farmingItem -> System.out.println(farmingItem.getKey() + ": " + farmingItem.getValue()));
  64.  
  65.  
  66. for (Map.Entry<String, Integer> junkItem : junk.entrySet()) {
  67. System.out.println(junkItem.getKey() + ": " + junkItem.getValue());
  68. }
  69. }
  70. }
Add Comment
Please, Sign In to add comment