Guest User

Baking Competition

a guest
Dec 13th, 2019
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.23 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class BakingCompetition {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int participantCount = Integer.parseInt(scanner.nextLine());
  8.  
  9.         double totalCount = 0;
  10.         double totalSum = 0.0;
  11.  
  12.         double priceCookies = 1.50;
  13.         double priceCakes = 7.80;
  14.         double priceWaffles = 2.30;
  15.  
  16.         for (int i = 0; i < participantCount; i++) {
  17.  
  18.             double cookiesCount = 0;
  19.             double cakesCount = 0;
  20.             double wafflesCount = 0;
  21.  
  22.             double cookiesSum = 0;
  23.             double cakesSum = 0;
  24.             double wafflesSum = 0;
  25.  
  26.  
  27.             String participantName = scanner.nextLine();
  28.             String sweetieType = scanner.nextLine();
  29.  
  30.             while (!sweetieType.equals("Stop baking!")) {
  31.                 int sweetieCount = Integer.parseInt(scanner.nextLine());
  32.  
  33.                 switch (sweetieType) {
  34.                    
  35.                     case "cookies":
  36.                         cookiesCount = sweetieCount;
  37.                         totalCount += cookiesCount;
  38.                         cookiesSum = cookiesCount * priceCookies;
  39.                         totalSum += cookiesSum;
  40.                         break;
  41.  
  42.                     case "cakes":
  43.                         cakesCount = sweetieCount;
  44.                         totalCount += cakesCount;
  45.                         cakesSum = cakesCount * priceCakes;
  46.                         totalSum += cakesSum;
  47.                         break;
  48.  
  49.                     case "waffles":
  50.                         wafflesCount = sweetieCount;
  51.                         totalCount += wafflesCount;
  52.                         wafflesSum = wafflesCount * priceWaffles;
  53.                         totalSum += wafflesSum;
  54.                         break;
  55.                 }
  56.                 sweetieType = scanner.nextLine();
  57.             }
  58.  
  59.             System.out.printf("%s baked %.0f cookies, %.0f cakes and %.0f waffles.%n", participantName, cookiesCount,
  60.                     cakesCount, wafflesCount);
  61.         }
  62.  
  63.         System.out.printf("All bakery sold: %.0f%n", totalCount);
  64.         System.out.printf("Total sum for charity: %.2f lv.%n", totalSum);
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment