Advertisement
Spocoman

Baking Competition

Sep 1st, 2024
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.42 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.         int bakers = Integer.parseInt(scanner.nextLine()),
  7.                 totalSweets = 0;
  8.         String command;
  9.         double totalSum = 0;
  10.  
  11.         for (int i = 0; i < bakers; i++) {
  12.             String baker = "", sweet = "";
  13.             int cookies = 0, cakes = 0, waffles = 0, sweetCount;
  14.  
  15.             while (!(command = scanner.nextLine()).equals("Stop baking!")) {
  16.                 if (baker.isEmpty()) {
  17.                     baker = command;
  18.                 } else {
  19.                     sweet = command;
  20.                     sweetCount = Integer.parseInt(scanner.nextLine());
  21.                     if (sweet.equals("cookies")) {
  22.                         cookies += sweetCount;
  23.                     } else if (sweet.equals("cakes")) {
  24.                         cakes += sweetCount;
  25.                     } else {
  26.                         waffles += sweetCount;
  27.                     }
  28.                     totalSweets += sweetCount;
  29.                 }
  30.             }
  31.             totalSum += 1.50 * cookies + 7.80 * cakes + 2.30 * waffles;
  32.             System.out.printf("%s baked %d cookies, %d cakes and %d waffles.\n", baker, cookies, cakes, waffles);
  33.         }
  34.  
  35.         System.out.printf("All bakery sold: %d\nTotal sum for charity: %.2f lv.\n", totalSweets, totalSum);
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement