deyanivanov966

EXAM 25.10 // 04. Cat Food

Oct 25th, 2020 (edited)
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 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.  
  7.         int cats = Integer.parseInt(scanner.nextLine());
  8.         int groupOne = 0;
  9.         int groupTwo = 0;
  10.         int groupThree = 0;
  11.         double totalFood = 0;
  12.  
  13.         for (int i = 1; i <= cats; i++) {
  14.             double food = Double.parseDouble(scanner.nextLine());;
  15.             totalFood += food;
  16.             if (food >= 100 && food < 200)
  17.             {
  18.                 groupOne++;
  19.             }
  20.             else if (food >= 200 && food < 300)
  21.             {
  22.                 groupTwo++;
  23.             }
  24.             else if (food >= 300 && food < 400)
  25.             {
  26.                 groupThree++;
  27.             }
  28.         }
  29.         double total = 0.0;
  30.         System.out.printf("Group 1: %d cats.%n", groupOne);
  31.         System.out.printf("Group 2: %d cats.%n" , groupTwo);
  32.         System.out.printf("Group 3: %d cats.%n", groupThree);
  33.         total = (totalFood / 1000) * 12.45;
  34.         System.out.printf("Price for food per day: %.2f lv.", total);
  35.     }
  36. }
Add Comment
Please, Sign In to add comment