Advertisement
IvaAnd

BakingCompetiotion_06

Mar 24th, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. import java.nio.charset.IllegalCharsetNameException;
  2. import java.util.Scanner;
  3.  
  4. public class BakingCompetition {
  5. public static void main(String[] args) {
  6. Scanner scanner = new Scanner(System.in);
  7.  
  8. int countCompetitors = Integer.parseInt(scanner.nextLine());
  9. int sumAllSweets = 0;
  10. double sumMoneyForCharity = 0;
  11.  
  12. for (int competitor = 0; competitor < countCompetitors; competitor++) {
  13. String competitorName = scanner.nextLine();
  14. String sweetType = scanner.nextLine();
  15. int countCookies = 0;
  16. int countCakes = 0;
  17. int countWaffles = 0;
  18.  
  19.  
  20. while (!sweetType.equals("Stop baking!")) {
  21. int countSweetsOfType = Integer.parseInt(scanner.nextLine());
  22.  
  23. switch (sweetType) {
  24. case "cookies":
  25. countCookies += countSweetsOfType;
  26. sumMoneyForCharity = countCookies * 1.5;
  27. break;
  28. case "cakes":
  29. countCakes += countSweetsOfType;
  30. sumMoneyForCharity += countCakes * 7.8;
  31. break;
  32. case "waffles":
  33. countWaffles += countSweetsOfType;
  34. sumMoneyForCharity += countWaffles * 2.3;
  35. break;
  36. }
  37. sweetType = scanner.nextLine();
  38. }
  39. sumAllSweets = sumAllSweets +countCookies + countCakes + countWaffles;
  40. System.out.printf("%s baked %d cookies, %d cakes and %d waffles.%n", competitorName, countCookies, countCakes, countWaffles);
  41.  
  42. }
  43. System.out.printf("All bakery sold: %d%n", sumAllSweets);
  44. System.out.printf("Total sum for charity: %.2f", sumMoneyForCharity);
  45.  
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement