Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ChristmasGifts {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int kidsCount = 0;
- int adultsCount = 0;
- double toyPrice = 5;
- double sweaterPrice = 15;
- double allToys = 0;
- double allSweaters = 0;
- String input = scanner.nextLine().trim();
- while (!input.equals("Christmas")) {
- int age = Integer.parseInt(input);
- if (age <= 16) {
- kidsCount++;
- } else {
- adultsCount++;
- }
- input = scanner.nextLine();
- double totalToysPrice = kidsCount * 1.0 * toyPrice;
- allToys = totalToysPrice;
- double totalSweatersPrice = adultsCount * 1.0 * sweaterPrice;
- allSweaters = totalSweatersPrice;
- }
- System.out.printf("Number of adults: %d%n", adultsCount);
- System.out.printf("Number of kids: %d%n", kidsCount);
- System.out.printf("Money for toys: %.0f%n", allToys);
- System.out.printf("Money for sweaters: %.0f%n", allSweaters);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement