Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.nio.charset.IllegalCharsetNameException;
- import java.util.Scanner;
- public class BakingCompetition {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int countCompetitors = Integer.parseInt(scanner.nextLine());
- int sumAllSweets = 0;
- double sumMoneyForCharity = 0;
- for (int competitor = 0; competitor < countCompetitors; competitor++) {
- String competitorName = scanner.nextLine();
- String sweetType = scanner.nextLine();
- int countCookies = 0;
- int countCakes = 0;
- int countWaffles = 0;
- while (!sweetType.equals("Stop baking!")) {
- int countSweetsOfType = Integer.parseInt(scanner.nextLine());
- switch (sweetType) {
- case "cookies":
- countCookies += countSweetsOfType;
- sumMoneyForCharity = countCookies * 1.5;
- break;
- case "cakes":
- countCakes += countSweetsOfType;
- sumMoneyForCharity += countCakes * 7.8;
- break;
- case "waffles":
- countWaffles += countSweetsOfType;
- sumMoneyForCharity += countWaffles * 2.3;
- break;
- }
- sweetType = scanner.nextLine();
- }
- sumAllSweets = sumAllSweets +countCookies + countCakes + countWaffles;
- System.out.printf("%s baked %d cookies, %d cakes and %d waffles.%n", competitorName, countCookies, countCakes, countWaffles);
- }
- System.out.printf("All bakery sold: %d%n", sumAllSweets);
- System.out.printf("Total sum for charity: %.2f", sumMoneyForCharity);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement