Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class CookieFactory {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int num = Integer.parseInt(scanner.nextLine());
  8.         int flour = 0;
  9.         int eggs = 0;
  10.         int sugar = 0;
  11.         int counter = 0;
  12.  
  13.         for (int i = 0; i < num; i++) {
  14.             String input = scanner.nextLine();
  15.  
  16.  
  17.             while (!input.equals("Bake!")) {
  18.                 if (input.equals("flour")) {
  19.                     flour++;
  20.                 } else if (input.equals("eggs")) {
  21.                     eggs++;
  22.                 } else if (input.equals("sugar")) {
  23.                     sugar++;
  24.                 }
  25.  
  26.                 input = scanner.nextLine();
  27.             }
  28.             if (flour >= 1 && eggs >= 1 && sugar >= 1) {
  29.                 flour = 0;
  30.                 eggs = 0;
  31.                 sugar = 0;
  32.                 counter++;
  33.  
  34.                 System.out.printf("Baking batch number %d...%n", counter);
  35.             } else {
  36.                 System.out.println("The batter should contain flour, eggs and sugar!");
  37.             }
  38.         }
  39.  
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement