desislava_topuzakova

04. Food for Pets

Feb 19th, 2022
1,063
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.75 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class PetFood_04 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int days = Integer.parseInt(scanner.nextLine());
  7.         double totalFood = Double.parseDouble(scanner.nextLine());
  8.  
  9.         double totalBiscuit = 0; //общо грамове бисквити
  10.         double totalEatenFoodForAllDays = 0; //общо изядена храна от кучето и котката общо за всички дни
  11.         double totalEatenDog = 0; //общо изядена храна от кучето
  12.         double totalEatenCat = 0; //общо изядена храна от котката
  13.  
  14.         for (int day = 1; day <= days; day++) {
  15.             int dogFood = Integer.parseInt(scanner.nextLine());
  16.             int catFood = Integer.parseInt(scanner.nextLine());
  17.             int foodPerDay = dogFood + catFood;
  18.             if (day % 3 == 0) { //всеки трети ден
  19.                 //бисквити
  20.                 totalBiscuit += 0.1 * foodPerDay;
  21.             }
  22.  
  23.             totalEatenFoodForAllDays += foodPerDay;
  24.             totalEatenDog += dogFood;
  25.             totalEatenCat += catFood;
  26.  
  27.         }
  28.  
  29.         System.out.printf("Total eaten biscuits: %.0fgr.%n", Math.round(totalBiscuit));
  30.         double percentEatenFood = totalEatenFoodForAllDays / totalFood * 100;
  31.         System.out.printf("%.2f%% of the food has been eaten.%n", percentEatenFood);
  32.         double percentDog = totalEatenDog / totalEatenFoodForAllDays * 100;
  33.         System.out.printf("%.2f%% eaten from the dog.%n", percentDog);
  34.         double percentCat = totalEatenCat / totalEatenFoodForAllDays * 100;
  35.         System.out.printf("%.2f%% eaten from the cat.", percentCat);
  36.     }
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment