kalin729

cocktails

Oct 23rd, 2021 (edited)
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.93 KB | None | 0 0
  1. package Exam;
  2.  
  3. import java.util.*;
  4.  
  5. public class AutumnCocktails {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         String[] bucketString = scanner.nextLine().split("\\s+");
  10.         String[] freshnessString = scanner.nextLine().split("\\s+");
  11.  
  12.         ArrayDeque<Integer> bucketValues = new ArrayDeque<>();
  13.         Stack<Integer> freshnessValues = new Stack<>();
  14.         Map<String, Integer> createdCocktails = new TreeMap<>();
  15.         createdCocktails.put("High Fashion", 0);
  16.         createdCocktails.put("Apple Hinny", 0);
  17.         createdCocktails.put("The Harvest", 0);
  18.         createdCocktails.put("Pear Sour", 0);
  19.  
  20.         Arrays.stream(bucketString).mapToInt(Integer::parseInt).forEach(bucketValues::offer);
  21.         Arrays.stream(freshnessString).mapToInt(Integer::parseInt).forEach(freshnessValues::push);
  22.  
  23.         while (!bucketValues.isEmpty() || !freshnessValues.isEmpty()) {
  24.             if (bucketValues.isEmpty() || freshnessValues.isEmpty()) {
  25.                 break;
  26.             }
  27.             int element1 = bucketValues.peek();
  28.             int element2 = freshnessValues.peek();
  29.             int localProd = element1 * element2;
  30.  
  31.             if (localProd == 150) {
  32.                 createdCocktails.put("Pear Sour", createdCocktails.get("Pear Sour") + 1);
  33.                 bucketValues.poll();
  34.                 freshnessValues.pop();
  35.             } else if (localProd == 250) {
  36.                 createdCocktails.put("The Harvest", createdCocktails.get("The Harvest") + 1);
  37.                 bucketValues.poll();
  38.                 freshnessValues.pop();
  39.             } else if (localProd == 300) {
  40.                 createdCocktails.put("Apple Hinny", createdCocktails.get("Apple Hinny") + 1);
  41.                 bucketValues.poll();
  42.                 freshnessValues.pop();
  43.             } else if (localProd == 400) {
  44.                 createdCocktails.put("High Fashion", createdCocktails.get("High Fashion") + 1);
  45.                 bucketValues.poll();
  46.                 freshnessValues.pop();
  47.             } else if (bucketValues.peek() == 0) {
  48.                 bucketValues.poll();
  49.             } else {
  50.                 freshnessValues.pop();
  51.                 bucketValues.offerLast(bucketValues.poll() + 5);
  52.             }
  53.  
  54.         }
  55.  
  56.         if (createdCocktails.containsValue(0)) {
  57.             System.out.println("What a pity! You didn't manage to prepare all cocktails.");
  58.         } else {
  59.             System.out.println("It's party time! The cocktails are ready!");
  60.         }
  61.  
  62.         int sum = bucketValues.stream().mapToInt(e -> e).sum();
  63.  
  64.         if (sum > 0) {
  65.             System.out.printf("Ingredients left: %d%n", sum);
  66.         }
  67.  
  68.         for (Map.Entry<String, Integer> entry : createdCocktails.entrySet()) {
  69.             if (entry.getValue() > 0) {
  70.                 System.out.printf("# %s --> %d%n", entry.getKey(), entry.getValue());
  71.             }
  72.         }
  73.  
  74.     }
  75. }
  76.  
Add Comment
Please, Sign In to add comment