desislava_topuzakova

05. Christmas Gifts

Nov 3rd, 2021
1,614
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.concurrent.ScheduledExecutorService;
  3.  
  4. public class P5 {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         String input = scanner.nextLine();
  9.  
  10.         int countToys = 0;
  11.         int countSweaters = 0;
  12.  
  13.         int pricePerToy = 5;
  14.         int pricePerSweater = 15;
  15.  
  16.         while (!input.equals("Christmas")) {
  17.             int age = Integer.parseInt(input);
  18.  
  19.  
  20.             if (age <= 16) {
  21.                 countToys ++;
  22.             } else {
  23.                 countSweaters ++;
  24.             }
  25.             input = scanner.nextLine();
  26.  
  27.         }
  28.         System.out.printf("Number of adults: %d%nNumber of kids: %d%nMoney for toys: %d%nMoney for sweaters: %d%n", countSweaters, countToys, countToys * pricePerToy, countSweaters * pricePerSweater);
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment