Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Exams.E28_29_2020;
- import java.util.Scanner;
- public class P04FoodForPets {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- //всеки трети ден бисквитки
- //бисквитките са 10 % от общо изядената храна
- int days = Integer.parseInt(scan.nextLine());
- double totalAmountFood = Double.parseDouble(scan.nextLine());
- int totalAmountFoodDog = 0;
- int totalAmountFoodCat = 0;
- int totalAmountEatenFood = 0;
- //int thirdDayFoodDog = 0; //clearing
- //int thirdDayFoodCat = 0; //clearing
- double biscuits = 0; //point 1
- for (int i = 1; i <= days; i++) {
- int amountFoodDogPerDay = Integer.parseInt(scan.nextLine());
- int amountFoodCatPerDay = Integer.parseInt(scan.nextLine());
- totalAmountFoodDog += amountFoodDogPerDay;
- totalAmountFoodCat += amountFoodCatPerDay;
- if(i % 3 == 0){ //point 1
- biscuits += (amountFoodDogPerDay + amountFoodCatPerDay) * 0.1; //point 1
- } //point 1
- }
- //int totalAmountthirdDay = thirdDayFoodCat + thirdDayFoodDog; //clearing
- totalAmountEatenFood = totalAmountFoodCat + totalAmountFoodDog;
- // int test1 = totalAmountFoodDog + 1000; //clearing
- // int test2 = totalAmountEatenFood + 1000; //clearing
- // double test3 = totalAmountFood / test2; //clearing
- // int biscuits = Math.round(totalAmountthirdDay * 10 / 100); //clearing
- double percentageFoodDog = (double)totalAmountFoodDog / totalAmountEatenFood; //point 2
- double percentageFoodCat = (double)totalAmountFoodCat / totalAmountEatenFood; //point 2
- System.out.printf("Total eaten biscuits: %dgr.%n", Math.round(biscuits)); //point 1
- System.out.printf("%.2f%% of the food has been eaten.%n", totalAmountEatenFood / totalAmountFood * 100.0);
- System.out.printf("%.2f%% eaten from the dog.%n", percentageFoodDog * 100.0);
- System.out.printf("%.2f%% eaten from the cat.%n", percentageFoodCat * 100.0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement