Advertisement
Lyubohd

06. Baking Competition

Feb 22nd, 2020
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.50 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Problem06 {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         int countOfBakers = Integer.parseInt(scan.nextLine());
  8.         double moneyGain = 0.0;
  9.         int totalCnt = 0;
  10.  
  11.         for (int i = 0; i < countOfBakers; i++) {
  12.             int cookiesCnt = 0;
  13.             int cakesCnt = 0;
  14.             int wafflesCnt = 0;
  15.             String bakerName = scan.nextLine();
  16.             String sweetType = scan.nextLine();
  17.             while (!sweetType.equals("Stop baking!")) {
  18.                 int sweetsCnt = Integer.parseInt(scan.nextLine());
  19.                 totalCnt += sweetsCnt;
  20.                 if (sweetType.equals("cookies")) {
  21.                     cookiesCnt += sweetsCnt;
  22.                     moneyGain += sweetsCnt * 1.50;
  23.                 } else if (sweetType.equals("cakes")) {
  24.                     cakesCnt += sweetsCnt;
  25.                     moneyGain += sweetsCnt * 7.80;
  26.                 } else if (sweetType.equals("waffles")) {
  27.                     wafflesCnt += sweetsCnt;
  28.                     moneyGain += sweetsCnt * 2.30;
  29.                 }
  30.                 sweetType = scan.nextLine();
  31.             }
  32.             System.out.printf("%s baked %d cookies, %d cakes and %d waffles.%n",
  33.                     bakerName, cookiesCnt, cakesCnt, wafflesCnt);
  34.         }
  35.  
  36.         System.out.printf("All bakery sold: %d%n", totalCnt);
  37.         System.out.printf("Total sum for charity: %.2f lv.", moneyGain);
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement