Advertisement
Valantina

BakingCompetition/Ex/27.07.2019/JAVA

Jul 29th, 2019
112
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 P06_BakingCompetition {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         int bakers = Integer.parseInt(scan.nextLine());
  8.  
  9.         double totalSum = 0.0;
  10.         int totalSweetsCnt = 0;
  11.  
  12.         for (int i = 0; i < bakers; i++) {
  13.             String bakerName = scan.nextLine();
  14.  
  15.             int cookiesCnt = 0;
  16.             int cakesCnt = 0;
  17.             int wafflesCnt = 0;
  18.  
  19.             String sweetName = scan.nextLine();
  20.             while (!"Stop baking!".equals(sweetName)) {
  21.                 int sweetsCnt = Integer.parseInt(scan.nextLine());
  22.                 switch (sweetName) {
  23.                     case "cookies":
  24.                         cookiesCnt += sweetsCnt;
  25.                         break;
  26.                     case "cakes":
  27.                         cakesCnt += sweetsCnt;
  28.                         break;
  29.                     case "waffles":
  30.                         wafflesCnt += sweetsCnt;
  31.                         break;
  32.                 }
  33.                 sweetName = scan.nextLine();
  34.             }
  35.             totalSum += ((cookiesCnt * 1.5) + (cakesCnt * 7.8) + (wafflesCnt * 2.3));
  36.             totalSweetsCnt += (cookiesCnt + cakesCnt + wafflesCnt);
  37.             System.out.println(String.format("%s baked %d cookies, %d cakes and %d waffles.",
  38.                     bakerName, cookiesCnt, cakesCnt, wafflesCnt));
  39.         }
  40.         System.out.println(String.format("All bakery sold: %d", totalSweetsCnt));
  41.         System.out.println(String.format("Total sum for charity: %.2f lv.", totalSum));
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement