Advertisement
Guest User

spaceship crafting

a guest
Aug 18th, 2019
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.48 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class spaceship {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         ArrayDeque<Integer> queueLiquids = new ArrayDeque<>();
  8.  
  9.         Arrays.stream(scanner.nextLine().split("\\s+"))
  10.                 .mapToInt(Integer::parseInt)
  11.                 .forEach(queueLiquids::offer);
  12.  
  13.         ArrayDeque<Integer> stackItems = new ArrayDeque<>();
  14.         Arrays.stream(scanner.nextLine().split("\\s+"))
  15.                 .mapToInt(Integer::parseInt)
  16.                 .forEach(stackItems::push);
  17.  
  18.         Map<String, Integer> elements = new LinkedHashMap<>();
  19.         elements.put("Glass", 0);
  20.         elements.put("Aluminium", 0);
  21.         elements.put("Lithium", 0);
  22.         elements.put("Carbon fiber", 0);
  23.         while (!queueLiquids.isEmpty() && !stackItems.isEmpty()) {
  24.             int currentLiquid = queueLiquids.poll();
  25.             int currentItem = stackItems.pop();
  26.  
  27.             int result = currentLiquid + currentItem;
  28.  
  29.             if (result == 25) {
  30.               int glass= elements.get("Glass")+1;
  31.               elements.put("Glass",glass);
  32.             } else if (result == 50) {
  33.                 int al=elements.get("Aluminium")+1;
  34.                 elements.put("Aluminium",al);
  35.             } else if (result == 75) {
  36.                int litium= elements.get("Lithium")+1;
  37.                elements.put("Lithium",litium);
  38.  
  39.             } else if (result == 100) {
  40.                 int add=elements.get("Carbon fiber")+1;
  41.                 elements.put("Carbon fiber",add);
  42.             } else {
  43.  
  44.                 currentItem += 3;
  45.                 stackItems.push(currentItem);
  46.             }
  47.         }
  48.         List<Integer>liquids=new ArrayList<>();
  49.         List<Integer>items=new ArrayList<>();
  50.         if (elements.get("Glass") > 0&&elements.get("Aluminium")>0&&elements.get("Lithium")>0&& elements.get("Carbon fiber")>0) {
  51.             System.out.println("Wohoo! You succeeded in building the spaceship!");
  52.         } else {
  53.             System.out.println("Ugh, what a pity! You didn't have enough materials to build the spaceship.");
  54.         }
  55.  
  56.         if (queueLiquids.isEmpty()) {
  57.             System.out.println("Liquids left: none");
  58.         } else {
  59.             System.out.print("Liquids left: ");
  60.             for (Integer liquid : queueLiquids) {
  61.                 liquids.add(liquid);
  62.             }
  63.             for (int i = 0; i < liquids.size(); i++) {
  64.                 if (i==liquids.size()-1){
  65.                     System.out.print(liquids.get(i));
  66.                 }else {
  67.                     System.out.print(liquids.get(i)+", ");
  68.                 }
  69.             }
  70.             System.out.println();
  71.         }
  72.  
  73.         if (stackItems.isEmpty()) {
  74.             System.out.println("Physical items left: none");
  75.         } else {
  76.             System.out.print("Physical items left: ");
  77.             for (Integer item : stackItems) {
  78.                 items.add(item);
  79.  
  80.             }
  81.             for (int i = 0; i < items.size(); i++) {
  82.                 if (i==items.size()-1){
  83.                     System.out.print(items.get(i));
  84.                 }else {
  85.                     System.out.print(items.get(i)+", ");
  86.                 }
  87.             }
  88.             System.out.println();
  89.         }
  90.  
  91.         elements.entrySet().stream().sorted((a, b) ->
  92.                 a.getKey().compareTo(b.getKey())).forEach(entry ->
  93.                 System.out.printf("%s: %d\n", entry.getKey(), entry.getValue()));
  94.  
  95.  
  96.     }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement