Advertisement
Guest User

Untitled

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