Advertisement
CoineTre

PreExam 11/20_04.Cat Food

Nov 18th, 2020
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class CatFood {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int catNumber = Integer.parseInt(scanner.nextLine());
  7.         int smallCats = 0;
  8.         int bigCats = 0;
  9.         int hugeCats = 0;
  10.         double gramFood = 0.0;
  11.         for (int i = 0; i < catNumber; i++) {
  12.             double food = Double.parseDouble(scanner.nextLine());
  13.             if(food < 200){
  14.                 gramFood +=food;
  15.                 smallCats++;
  16.             }else if(food < 300){
  17.                 gramFood +=food;
  18.                 bigCats ++;
  19.             }else if(food < 400){
  20.                 gramFood+=food;
  21.                 hugeCats ++;
  22.             }
  23.         }
  24.         double moneyForFood = gramFood /1000 * 12.45;
  25.         System.out.printf("Group 1: %d cats.%n",smallCats);
  26.         System.out.printf("Group 2: %d cats.%n",bigCats);
  27.         System.out.printf("Group 3: %d cats.%n",hugeCats);
  28.         System.out.printf("Price for food per day: %.2f lv.",moneyForFood);
  29.     }
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement