Advertisement
Spocoman

Food for Pets

Sep 6th, 2024
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. import java.io.PrintStream;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.         int days = Integer.parseInt(scanner.nextLine()),
  8.                 dailyDogFood, dailyCatFood, eatenDogsFood = 0, eatenCatsFood = 0;
  9.         double availableFood = Double.parseDouble(scanner.nextLine()), cookies = 0;
  10.  
  11.         for (int i = 1; i <= days; i++) {
  12.             dailyDogFood = Integer.parseInt(scanner.nextLine());
  13.             dailyCatFood = Integer.parseInt(scanner.nextLine());
  14.  
  15.             if (i % 3 == 0) {
  16.                 cookies += 0.1 * (dailyDogFood + dailyCatFood);
  17.             }
  18.             eatenDogsFood += dailyDogFood;
  19.             eatenCatsFood += dailyCatFood;
  20.         }
  21.  
  22.         double totalEatenFood = eatenDogsFood + eatenCatsFood;
  23.  
  24.         System.out.printf("Total eaten biscuits: %dgr.\n", (int) Math.round(cookies));
  25.         System.out.printf("%.2f%% of the food has been eaten.\n", 100.0 * totalEatenFood / availableFood);
  26.         System.out.printf("%.2f%% eaten from the dog.\n", 100.0 * eatenDogsFood / totalEatenFood);
  27.         System.out.printf("%.2f%% eaten from the cat.\n", 100.0 * eatenCatsFood / totalEatenFood);
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement