Advertisement
galinyotsev123

ProgBasics07Nested-Loops-P08cookieFactory2

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