Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.52 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class demo {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int competitors = Integer.parseInt(scanner.nextLine());
  7.         int allCakes = 0;
  8.         double price = 0;
  9.         for (int i = 0; i < competitors; i++) {
  10.             String name = scanner.nextLine();
  11.             String cakeType = scanner.nextLine();
  12.             int cntCookies = 0;
  13.             int cntCakes = 0;
  14.             int cntWaffles = 0;
  15.             while (!cakeType.equals("Stop baking!")) {
  16.                 int count = Integer.parseInt(scanner.nextLine());
  17.                 allCakes += count;
  18.                 switch (cakeType) {
  19.                     case "cookies":
  20.                         cntCookies += count;
  21.                         price += cntCookies * 1.5;
  22.                         break;
  23.                     case "cakes":
  24.                         cntCakes += count;
  25.                         price += cntCakes * 7.8;
  26.                         break;
  27.                     case "waffles":
  28.                         cntWaffles += count;
  29.                         price += cntWaffles * 2.3;
  30.                         break;
  31.                 }
  32.                 cakeType = scanner.nextLine();
  33.             }
  34.             System.out.printf("%s baked %d cookies, %d cakes and %d waffles.%n", name, cntCookies, cntCakes, cntWaffles);
  35.         }
  36.         System.out.printf("All bakery sold: %d%n", allCakes);
  37.         System.out.printf("Total sum for charity: %.2f lv.", price);
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement