Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Map;
- import java.util.Scanner;
- import java.util.TreeMap;
- public class Ex03_LegendaryFarming {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- Map<String, Integer> farming = new TreeMap<>();
- Map<String, Integer> junk = new TreeMap<>();
- farming.put("shards", 0);
- farming.put("fragments", 0);
- farming.put("motes", 0);
- boolean legenderyReached = false;
- while (!legenderyReached) {
- String[] input = scanner.nextLine().split(" ");
- for (int i = 0; i < input.length; i = i + 2) {
- int quantity = Integer.parseInt(input[i]);
- String material = input[i + 1].toLowerCase();
- int sum = 0;
- if (farming.containsKey(material)) {
- sum = farming.get(material) + quantity;
- farming.put(material, sum);
- } else {
- if (!junk.containsKey(material)) {
- junk.put(material, quantity);
- } else {
- sum = junk.get(material) + quantity;
- junk.put(material, sum);
- }
- }
- if (farming.get("shards") >= 250
- || farming.get("fragments") >= 250
- || farming.get("motes") >= 250) {
- if (material.equals("shards")) {
- System.out.println("Shadowmourne obtained!");
- } else if (material.equals("fragments")) {
- System.out.println("Valanyr obtained!");
- } else {
- System.out.println("Dragonwrath obtained!");
- }
- int finalQuantity = farming.get(material) - 250;
- farming.put(material, finalQuantity);
- legenderyReached = true;
- break;
- }
- }
- }
- farming.entrySet().stream().sorted((f, s) -> {
- int result = s.getValue().compareTo(f.getValue());
- if (result == 0) {
- result = f.getKey().compareTo(s.getKey());
- }
- return result;
- }).forEach(farmingItem -> System.out.println(farmingItem.getKey() + ": " + farmingItem.getValue()));
- for (Map.Entry<String, Integer> junkItem : junk.entrySet()) {
- System.out.println(junkItem.getKey() + ": " + junkItem.getValue());
- }
- }
- }
Add Comment
Please, Sign In to add comment