grach

Food For Pets exam 28-29 March 2020

Apr 9th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class FoodForPets {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.  
  8.         int days = Integer.parseInt(scan.nextLine());
  9.         double totalFood = Double.parseDouble(scan.nextLine());
  10.  
  11. double cookies = 0;
  12. double cats=0;
  13. double dogs=0;
  14. double eatenFood = totalFood;
  15.  
  16.         for (int i = 0; i <days ; i++) {
  17.             double dogFood = Double.parseDouble(scan.nextLine());
  18.             double catFood = Double.parseDouble(scan.nextLine());
  19.             dogs = dogs+dogFood;
  20.             cats= cats+catFood;
  21.             eatenFood=dogs+cats;
  22.  
  23.             if (days % 3 == 0) {
  24.                // System.out.println(dogFood+catFood);
  25.                 cookies=(dogFood+catFood)*0.1;
  26.                 //cookies++;
  27.             }
  28.         }
  29.         System.out.printf("Total eaten biscuits: %.0fgr.%n",cookies);
  30.         System.out.printf("%.2f%% of the food has been eaten.%n",eatenFood/totalFood*100);
  31.         System.out.printf("%.2f%% eaten from the dog.%n",dogs/eatenFood*100);
  32.         System.out.printf("%.2f%% eaten from the cat.",cats/eatenFood*100);
  33.     }
  34. }
Add Comment
Please, Sign In to add comment