stoyanoff

FoodForPets

Jul 27th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.39 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class FoodforPets {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int day = Integer.parseInt(scanner.nextLine());
  8.         double food = Double.parseDouble(scanner.nextLine());
  9.  
  10.         int dogEat = 0;
  11.         int catEat = 0;
  12.         int dogPerDay = 0;
  13.         int catPerDay = 0;
  14.         double biscuits = 0;
  15.         double totalBiscuits = 0;
  16.  
  17.         double sumFood = 0;
  18.         for (int i = 1; i <= day; i++) {
  19.  
  20.             dogEat = Integer.parseInt(scanner.nextLine());
  21.             catEat = Integer.parseInt(scanner.nextLine());
  22.  
  23.             dogPerDay += dogEat;
  24.             catPerDay += catEat;
  25.             sumFood = dogPerDay + catPerDay;
  26.  
  27.             if (i % 3 == 0) {
  28.                 biscuits = ( dogEat + catEat ) * 0.10;
  29.                 totalBiscuits += biscuits;
  30.             }
  31.         }
  32.         double foodEaten = ( sumFood / food ) * 100;
  33.         double foodEatenDog = ( dogPerDay / sumFood ) * 100;
  34.         double foodEatenCat = ( catPerDay / sumFood ) * 100;
  35.         System.out.printf("Total eaten biscuits: %dgr.%n", Math.round(totalBiscuits));
  36.         System.out.printf("%.2f%% of the food has been eaten.%n", foodEaten);
  37.         System.out.printf("%.2f%% eaten from the dog.%n", foodEatenDog);
  38.         System.out.printf("%.2f%% eaten from the cat.%n", foodEatenCat);
  39.     }
  40. }
Add Comment
Please, Sign In to add comment