Advertisement
IvaAnd

Bomb/Exam 28JUN20

Oct 20th, 2020
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. package Exam20200628;
  2.  
  3. import com.sun.security.jgss.GSSUtil;
  4.  
  5. import java.util.*;
  6.  
  7. public class Bombs {
  8. public static void main(String[] args) {
  9. Scanner scanner = new Scanner(System.in);
  10.  
  11. int[] line = Arrays.stream(scanner.nextLine().split(", "))
  12. .mapToInt(Integer::parseInt).toArray();
  13.  
  14. ArrayDeque<Integer> queEffect = new ArrayDeque();
  15.  
  16. for (int i = 0; i < line.length; i++) {
  17. queEffect.offer(line[i]);
  18. }
  19.  
  20. line = Arrays.stream(scanner.nextLine().split(", "))
  21. .mapToInt(Integer::parseInt).toArray();
  22. ArrayDeque<Integer> staCasings = new ArrayDeque();
  23. for (int i = 0; i < line.length; i++) {
  24. staCasings.push(line[i]);
  25. }
  26.  
  27. Map<String, Integer> bombs = new TreeMap<>();
  28. bombs.put("Datura Bombs", 0);
  29. bombs.put("Cherry Bombs", 0);
  30. bombs.put("Smoke Decoy Bombs", 0);
  31.  
  32. boolean isFull = false;
  33.  
  34. while (queEffect.size() > 0 && staCasings.size() > 0 && !isFull) {
  35. int effect = queEffect.peek();
  36. int casing = staCasings.peek();
  37. int result = effect + casing;
  38.  
  39. while (result != 40 && result != 60 && result != 120) {
  40. result -= 5;
  41. }
  42. switch (result) {
  43. case 40:
  44. String currentBomb = "Datura Bombs";
  45. bombs.put(currentBomb, bombs.get(currentBomb) + 1);
  46. break;
  47. case 60:
  48. bombs.put("Cherry Bombs", bombs.get("Cherry Bombs") + 1);
  49. break;
  50. case 120:
  51. bombs.put("Smoke Decoy Bombs", bombs.get("Smoke Decoy Bombs") + 1);
  52. break;
  53. }
  54.  
  55. if (bombs.get("Cherry Bombs") >= 3 && bombs.get("Datura Bombs") >= 3 && bombs.get("Smoke Decoy Bombs") >= 3) {
  56. isFull = true;
  57. }
  58. queEffect.poll();
  59. staCasings.pop();
  60.  
  61. }
  62.  
  63. if (isFull) {
  64. System.out.println("Bene! You have successfully filled the bomb pouch!");
  65. } else {
  66. System.out.println("You don't have enough materials to fill the bomb pouch.");
  67. }
  68.  
  69. StringBuilder builder = new StringBuilder();
  70. String output = queEffect.size() == 0 ? "Bomb Effects: empty" : "Bomb Effects: ";
  71. builder.append(output);
  72.  
  73. for (Integer integer : queEffect) {
  74. builder.append(String.valueOf(integer));
  75. }
  76. System.out.println(String.join(", ", builder));
  77.  
  78. builder = new StringBuilder();
  79. output = staCasings.size() == 0 ? "Bomb Casings: empty" : "Bomb Casings: ";
  80. builder.append(output);
  81. for (Integer integer : staCasings) {
  82. builder.append(String.valueOf(integer));
  83. }
  84. System.out.println(String.join(", ", builder));
  85.  
  86. if (!bombs.isEmpty()) {
  87. bombs.entrySet().forEach(item ->
  88. System.out.printf("%s: %d%n", item.getKey(), item.getValue()));
  89. }
  90. }
  91. }
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement