Advertisement
CR7CR7

GIFT

Feb 26th, 2023
989
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ChristmasGifts {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int kidsCount = 0;
  8.  
  9.         int adultsCount = 0;
  10.  
  11.         double toyPrice = 5;
  12.  
  13.         double sweaterPrice = 15;
  14.  
  15.         double allToys = 0;
  16.  
  17.         double allSweaters = 0;
  18.  
  19.         String input = scanner.nextLine().trim();
  20.  
  21.         while (!input.equals("Christmas")) {
  22.  
  23.             int age = Integer.parseInt(input);
  24.  
  25.             if (age <= 16) {
  26.  
  27.  
  28.                 kidsCount++;
  29.             } else {
  30.  
  31.  
  32.                 adultsCount++;
  33.             }
  34.  
  35.  
  36.             input = scanner.nextLine();
  37.  
  38.             double totalToysPrice = kidsCount * 1.0 * toyPrice;
  39.             allToys = totalToysPrice;
  40.  
  41.             double totalSweatersPrice = adultsCount * 1.0 * sweaterPrice;
  42.             allSweaters = totalSweatersPrice;
  43.         }
  44.  
  45.         System.out.printf("Number of adults: %d%n", adultsCount);
  46.         System.out.printf("Number of kids: %d%n", kidsCount);
  47.         System.out.printf("Money for toys: %.0f%n", allToys);
  48.         System.out.printf("Money for sweaters: %.0f%n", allSweaters);
  49.  
  50.  
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement