Advertisement
Guest User

Untitled

a guest
Oct 20th, 2022
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.27 KB | None | 0 0
  1. package Exams.E28_29_2020;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P04FoodForPets {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner scan = new Scanner(System.in);
  9.  
  10.         //всеки трети ден бисквитки
  11.         //бисквитките са 10 % от общо изядената храна
  12.  
  13.         int days = Integer.parseInt(scan.nextLine());
  14.         double totalAmountFood = Double.parseDouble(scan.nextLine());
  15.  
  16.         int totalAmountFoodDog = 0;
  17.         int totalAmountFoodCat = 0;
  18.         int totalAmountEatenFood = 0;
  19.  
  20.         //int thirdDayFoodDog = 0;  //clearing
  21.         //int thirdDayFoodCat = 0;  //clearing
  22.         double biscuits = 0;    //point 1
  23.         for (int i = 1; i <= days; i++) {
  24.             int amountFoodDogPerDay = Integer.parseInt(scan.nextLine());
  25.             int amountFoodCatPerDay = Integer.parseInt(scan.nextLine());
  26.  
  27.             totalAmountFoodDog += amountFoodDogPerDay;
  28.             totalAmountFoodCat += amountFoodCatPerDay;
  29.  
  30.             if(i % 3 == 0){                                                       //point 1
  31.                 biscuits += (amountFoodDogPerDay + amountFoodCatPerDay) * 0.1;    //point 1
  32.             }                                                                     //point 1
  33.         }
  34.         //int totalAmountthirdDay = thirdDayFoodCat + thirdDayFoodDog;  //clearing
  35.         totalAmountEatenFood = totalAmountFoodCat + totalAmountFoodDog;
  36.  
  37.        // int test1 = totalAmountFoodDog + 1000;    //clearing
  38.        // int test2 = totalAmountEatenFood + 1000;  //clearing
  39.        // double test3 = totalAmountFood / test2;   //clearing
  40.  
  41.        // int biscuits = Math.round(totalAmountthirdDay * 10 / 100);    //clearing
  42.  
  43.         double percentageFoodDog = (double)totalAmountFoodDog / totalAmountEatenFood;   //point 2
  44.         double percentageFoodCat = (double)totalAmountFoodCat / totalAmountEatenFood;   //point 2
  45.  
  46.         System.out.printf("Total eaten biscuits: %dgr.%n", Math.round(biscuits));   //point 1
  47.         System.out.printf("%.2f%% of the food has been eaten.%n", totalAmountEatenFood / totalAmountFood * 100.0);
  48.         System.out.printf("%.2f%% eaten from the dog.%n", percentageFoodDog * 100.0);
  49.         System.out.printf("%.2f%% eaten from the cat.%n", percentageFoodCat * 100.0);
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement