View difference between Paste ID: DSce3NbL and 2Ya5gczB
SHOW: | | - or go back to the newest paste.
1
package FundamentalsModule.AssociativeArrays.MoreExercises;
2
3
import java.util.*;
4
5
6
public class LegendaryFarming {
7
8
    public static void main(String[] args) {
9
10
        Scanner scanner = new Scanner(System.in);
11
12
        Map<String, Integer> junk = new HashMap<>();
13
14
        Map<String, Integer> keyMaterials = new HashMap<>();
15
        String shadowmourneSh = "shards";
16
        String valanyrFr = "fragments";
17
        String dragonwrathMo = "motes";
18
19
        String obtained = "";
20
        String resKeyValue = "";
21
22
        keyMaterials.put(valanyrFr, 0);
23
        keyMaterials.put(shadowmourneSh, 0);
24
        keyMaterials.put(dragonwrathMo, 0);
25
26
        boolean isObtained = false;
27
28
        do {
29
30
            String[] materials = scanner.nextLine().split(" ");
31
32
            for (int i = 1; i < materials.length; i += 2) {
33
34
                String currMaterial = materials[i].toLowerCase();
35
                int currAmount = Integer.parseInt(materials[i - 1]);
36
37
                if (currMaterial.equals(shadowmourneSh) || currMaterial.equals(valanyrFr) || currMaterial.equals(dragonwrathMo)) {
38
39
                    keyMaterials.put(currMaterial, keyMaterials.get(currMaterial) + currAmount);
40
41
                    if (keyMaterials.get(currMaterial) >= 250) {
42
43
                        if (currMaterial.equals(shadowmourneSh)) {
44
45
                            obtained = "Shadowmourne";
46
47
48
                        } else if (currMaterial.equals(valanyrFr)) {
49
50
                            obtained = "Valanyr";
51
52
53
                        } else {
54
55
                            obtained = "Dragonwrath";
56
                        }
57
58
                        resKeyValue = currMaterial;
59
60
                        isObtained = true;
61
                        break;
62
                    }
63
64
                } else {
65
66
                    junk.putIfAbsent(currMaterial, 0);
67
                    junk.put(currMaterial, junk.get(currMaterial) + currAmount);
68
                }
69
70
            }
71
72
        } while (!isObtained);
73
74
        keyMaterials.put(resKeyValue, keyMaterials.get(resKeyValue) - 250);
75
76
        System.out.println(obtained + " obtained!");
77
78
        keyMaterials
79
                .keySet()
80
                .stream()
81
                .sorted(String::compareTo)
82
                .sorted((e1, e2) -> keyMaterials.get(e2).compareTo(keyMaterials.get(e1)))
83
                .forEach(e -> System.out.println(e + ": " + keyMaterials.get(e)));
84
85
        junk
86
                .keySet()
87
                .stream().sorted()
88
                .forEach(e -> System.out.println(e + ": " + junk.get(e)));
89
90
91
    }
92
}
93