desislava_topuzakova

04. Food for Pets

Mar 31st, 2020
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.26 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class FoodForPets_04 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int days = Integer.parseInt(scanner.nextLine());
  7.         double availableFood = Double.parseDouble(scanner.nextLine());
  8.  
  9.         double totalDog = 0;
  10.         double totalCat = 0;
  11.         double total = 0;
  12.         double totalBiscuits = 0;
  13.  
  14.         for (int day = 1; day <= days ; day++) {
  15.             int dog = Integer.parseInt(scanner.nextLine());
  16.             int cat = Integer.parseInt(scanner.nextLine());
  17.  
  18.             totalDog += dog;
  19.             totalCat += cat;
  20.             total += dog + cat;
  21.  
  22.             if(day % 3 == 0) {
  23.                 totalBiscuits += 0.10 * (dog + cat);
  24.             }
  25.         }
  26.  
  27.         System.out.printf("Total eaten biscuits: %dgr.%n", Math.round(totalBiscuits));
  28.         double percentEaten = total / availableFood * 100;
  29.         System.out.printf("%.2f%% of the food has been eaten.%n", percentEaten);
  30.         double percentByDog = totalDog / total * 100;
  31.         System.out.printf("%.2f%% eaten from the dog.%n", percentByDog);
  32.         double percentByCat= totalCat / total * 100;
  33.         System.out.printf("%.2f%% eaten from the cat.", percentByCat);
  34.     }
  35. }
Add Comment
Please, Sign In to add comment