Advertisement
Guest User

Untitled

a guest
Nov 6th, 2021
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.65 KB | None | 0 0
  1. package JavaFundamentals;
  2.  
  3. import java.util.*;
  4.  
  5. public class LegendaryFarming {
  6.     public static void main(String[] args) {
  7.  
  8.         Scanner scan = new Scanner(System.in);
  9.  
  10.         String[] line;
  11.  
  12.         Map<String, Integer> specialItems = new HashMap<>();
  13.         Map<String, Integer> junk = new TreeMap<>();
  14.  
  15.         int quantity;
  16.         String item;
  17.         boolean breakable = false;
  18.  
  19.         specialItems.put("shards", 0);
  20.         specialItems.put("fragments", 0);
  21.         specialItems.put("motes", 0);
  22.  
  23.         while (true) {
  24.             line = scan.nextLine().split(" ");
  25.             for (int i = 0; i < line.length; i++) {
  26.                 if (i % 2 == 0) {
  27.                     quantity = Integer.parseInt(line[i]);
  28.                     item = line[i + 1];
  29.                 } else {
  30.                     continue;
  31.                 }
  32.                 item = item.toLowerCase();
  33.                 if (item.equals("shards") || item.equals("fragments") || item.equals("motes")) {
  34.                     specialItems.put(item, specialItems.get(item) + quantity);
  35.                     if (specialItems.get(item) >= 250) {
  36.                         specialItems.put(item, specialItems.get(item) - 250);
  37.                         if (item.equals("shards")) {
  38.                             System.out.println("Shadowmourne obtained!");
  39.                         }
  40.                         if (item.equals("fragments")) {
  41.                             System.out.println("Valanyr obtained!");
  42.                         }
  43.                         if (item.equals("motes")) {
  44.                             System.out.println("Dragonwrath obtained!");
  45.                         }
  46.                         breakable = true;
  47.                         break;
  48.                     }
  49.                 } else {
  50.                     if (!junk.containsKey(item)) {
  51.                         junk.put(item, 0);
  52.                     }
  53.                     junk.put(item, junk.get(item) + quantity);
  54.                 }
  55.             }
  56.             if (breakable == true) {
  57.                 break;
  58.             }
  59.         }
  60.  
  61.         specialItems.entrySet().stream()
  62.                 .sorted((Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) -> {
  63.                     return o2.getValue().equals(o1.getValue()) ?
  64.                             o1.getKey().compareTo(o2.getKey())
  65.                             : o2.getValue().compareTo(o1.getValue());
  66.                 }).forEach(e -> System.out.println(e.getKey() + ": " + e.getValue()));
  67.  
  68.         for (Map.Entry<String, Integer> entry : junk.entrySet()) {
  69.             System.out.println(entry.getKey() + ": " + entry.getValue());
  70.  
  71.         }
  72.  
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement