Didart

Legendary Farming

Jan 20th, 2023
1,282
0
Never
4
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.72 KB | None | 0 0
  1. package SetsAndMaps3;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Map;
  5. import java.util.Scanner;
  6. import java.util.TreeMap;
  7.  
  8. public class LegendaryFarming {
  9.     public static void main(String[] args) {
  10.         Scanner scanner = new Scanner(System.in);
  11.  
  12.         boolean isObtained = false;
  13.  
  14.         Map<String, Integer> keyMaterials = new HashMap<>();
  15.         keyMaterials.put("motes", 0);
  16.         keyMaterials.put("shards", 0);
  17.         keyMaterials.put("fragments", 0);
  18.  
  19.         Map<String, Integer> junk = new TreeMap<>();
  20.  
  21.  
  22.         while (!isObtained) {
  23.             String[] materials = scanner.nextLine().split("\\s+");
  24.  
  25.             for (int i = 0; i < materials.length - 1; i += 2) {
  26.                 int quantity = Integer.parseInt(materials[i]);
  27.                 String item = materials[i + 1].toLowerCase();
  28.  
  29.                 if (item.equals("motes") || item.equals("shards") || item.equals("fragments")) {
  30.                     keyMaterials.put(item, keyMaterials.get(item) + quantity);
  31.  
  32.                     if (keyMaterials.get(item) >= 250) {
  33.                         keyMaterials.put(item, keyMaterials.get(item) - 250);
  34.                         if (item.equals("motes")) {
  35.                             System.out.println("Dragonwrath obtained!");
  36.                             isObtained = true;
  37.                             break;
  38.  
  39.                         } else if (item.equals("shards")) {
  40.                             System.out.println("Shadowmourne obtained!");
  41.                             isObtained = true;
  42.                             break;
  43.                         } else {
  44.                             System.out.println("Valanyr obtained!");
  45.                             isObtained = true;
  46.                             break;
  47.                         }
  48.                     }
  49.  
  50.                 } else {
  51.                     if (!junk.containsKey(item)) {
  52.                         junk.put(item, quantity);
  53.  
  54.                     } else {
  55.                         junk.put(item, junk.get(item) + quantity);
  56.                     }
  57.                 }
  58.             }
  59.         }
  60.         keyMaterials
  61.                 .entrySet()
  62.                 .stream()
  63.                 .sorted((a, b) -> {
  64.                     if (b.getValue() - a.getValue() == 0) {
  65.                         return a.getKey()
  66.                                 .compareTo(b.getKey());
  67.                     } else {
  68.                         return b.getValue() - a.getValue();
  69.                     }
  70.                 }).forEach(entry -> System.out.printf("%s: %d%n", entry.getKey(), entry.getValue()));
  71.  
  72.         for (Map.Entry<String, Integer> token : junk.entrySet()) {
  73.             System.out.printf("%s: %d%n", token.getKey(), token.getValue());
  74.         }
  75.     }
  76. }
  77.  
Advertisement
Comments
  • Beech20
    2 years
    # text 0.13 KB | 0 0
    1. Hi there Im New today I tried to create my 35 links but it was impossible to validate my stuffs at the end does pastebin works zctually?
    • Didart
      2 years
      # text 0.26 KB | 0 0
      1. Hello! You choose the green button above + paste. First you put the code, below it there are fields that you need to fill. Here - Syntax Highlighting:, here - Paste Expiration:, here - Paste Exposure:and here - Paste Name / Title:
      2. Next step Save Changes. That's all.
  • Beech20
    2 years
    # text 0.02 KB | 0 0
    1. Ok I will try again
    • Didart
      2 years
      Comment was deleted
Add Comment
Please, Sign In to add comment