Advertisement
GabrielHr00

04. Food for Pets

Feb 15th, 2025
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.56 KB | None | 0 0
  1. package examPreparation;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class FoodForPets {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         int daysCount = Integer.parseInt(scanner.nextLine());
  9.         double foodQuantity = Double.parseDouble(scanner.nextLine());
  10.  
  11.         double totalCountBiscuits = 0.0;
  12.         double allEatenFood = 0.0;
  13.         double dogEatenFood = 0.0;
  14.         double catEatenFood = 0.0;
  15.  
  16.         for (int i = 1; i <= daysCount; i++) {
  17.             int dogFood = Integer.parseInt(scanner.nextLine());
  18.             int catFood = Integer.parseInt(scanner.nextLine());
  19.  
  20.             dogEatenFood += dogFood;
  21.             catEatenFood += catFood;
  22.  
  23.             double biscuits = 0.0;
  24.             int dailyFood = dogFood + catFood;
  25.             allEatenFood += dailyFood;
  26.  
  27.             if (i % 3 == 0) {
  28.                 biscuits = dailyFood * 0.10;
  29.                 totalCountBiscuits += biscuits;
  30.             }
  31.         }
  32.  
  33.  
  34.         //•   "{процент изядена храна от кучето}% eaten from the dog."
  35.         //•   "{процент изядена храна от котката}% eaten from the cat."
  36.         System.out.printf("Total eaten biscuits: %.0fgr.%n", totalCountBiscuits);
  37.         System.out.printf("%.2f%% of the food has been eaten.%n", allEatenFood / foodQuantity * 100);
  38.         System.out.printf("%.2f%% eaten from the dog.%n", dogEatenFood / allEatenFood * 100);
  39.         System.out.printf("%.2f%% eaten from the cat.", catEatenFood / allEatenFood * 100);
  40.  
  41.     }
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement