Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class BakingCompetition {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int participantCount = Integer.parseInt(scanner.nextLine());
- double totalCount = 0;
- double totalSum = 0.0;
- double priceCookies = 1.50;
- double priceCakes = 7.80;
- double priceWaffles = 2.30;
- for (int i = 0; i < participantCount; i++) {
- double cookiesCount = 0;
- double cakesCount = 0;
- double wafflesCount = 0;
- double cookiesSum = 0;
- double cakesSum = 0;
- double wafflesSum = 0;
- String participantName = scanner.nextLine();
- String sweetieType = scanner.nextLine();
- while (!sweetieType.equals("Stop baking!")) {
- int sweetieCount = Integer.parseInt(scanner.nextLine());
- switch (sweetieType) {
- case "cookies":
- cookiesCount = sweetieCount;
- totalCount += cookiesCount;
- cookiesSum = cookiesCount * priceCookies;
- totalSum += cookiesSum;
- break;
- case "cakes":
- cakesCount = sweetieCount;
- totalCount += cakesCount;
- cakesSum = cakesCount * priceCakes;
- totalSum += cakesSum;
- break;
- case "waffles":
- wafflesCount = sweetieCount;
- totalCount += wafflesCount;
- wafflesSum = wafflesCount * priceWaffles;
- totalSum += wafflesSum;
- break;
- }
- sweetieType = scanner.nextLine();
- }
- System.out.printf("%s baked %.0f cookies, %.0f cakes and %.0f waffles.%n", participantName, cookiesCount,
- cakesCount, wafflesCount);
- }
- System.out.printf("All bakery sold: %.0f%n", totalCount);
- System.out.printf("Total sum for charity: %.2f lv.%n", totalSum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment