Advertisement
valiamaximova1

Food For Pets

Apr 14th, 2020
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.51 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class FoodForDogs {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         int days = Integer.parseInt(scan.nextLine());
  8.         double kolichestvoHrana = Double.parseDouble(scan.nextLine());
  9.         double dogFood = 0;
  10.         double catFood = 0;
  11.         double obshto = 0;
  12.         double biscuits = 0;
  13.         double obshoDog = 0;
  14.         double obshoCat = 0;
  15.         double obshtoObshto = 0;
  16.         double bisss = 0;
  17.  
  18.         for (int i = 1; i <= days; i++) {
  19.             dogFood = Double.parseDouble(scan.nextLine());
  20.             catFood = Double.parseDouble(scan.nextLine());
  21.             obshto = dogFood + catFood;
  22.             obshoDog = obshoDog + dogFood;
  23.             obshoCat = obshoCat + catFood;
  24.             obshtoObshto = obshtoObshto + obshto;
  25.  
  26.  
  27.             if (i % 3 == 0) {
  28.                 biscuits =  obshto * 0.1;
  29.                 bisss = bisss + biscuits;
  30.  
  31.             }
  32.  
  33.  
  34.         }
  35.         double resultIzqdena = obshtoObshto / kolichestvoHrana * 100;
  36.         double resultDog = obshoDog / obshtoObshto * 100;
  37.         double result = obshoCat / obshtoObshto * 100;
  38.         double biss = Math.abs(bisss);
  39.  
  40.         System.out.printf("Total eaten biscuits: %.0fgr.", biss);
  41.         System.out.printf("%n%.2f%% of the food has been eaten.", resultIzqdena);
  42.         System.out.printf("%n%.2f%% eaten from the dog.", resultDog);
  43.         System.out.printf("%n%.2f%% eaten from the cat.", result);
  44.  
  45.  
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement