Advertisement
Guest User

Untitled

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