Advertisement
veronikaaa86

04. Food for Pets

Nov 13th, 2021
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. package examPrep;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P04FoodForPets {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. int countDays = Integer.parseInt(scanner.nextLine());
  10. double availableFood = Double.parseDouble(scanner.nextLine());
  11.  
  12. double totalFood = 0;
  13. double dogFood = 0;
  14. double catFood = 0;
  15. double totalBiscuits = 0;
  16. for (int i = 1; i <= countDays; i++) {
  17. int dogFoodCurrent = Integer.parseInt(scanner.nextLine());
  18. int catFoodCurrent = Integer.parseInt(scanner.nextLine());
  19.  
  20. dogFood = dogFood + dogFoodCurrent;
  21. catFood = catFood + catFoodCurrent;
  22.  
  23. double totalFoodCurrentDay = dogFoodCurrent + catFoodCurrent;
  24.  
  25. if (i % 3 == 0) {
  26. totalBiscuits = totalBiscuits + (totalFoodCurrentDay * 0.10);
  27. }
  28.  
  29. totalFood = totalFood + (totalFoodCurrentDay);
  30. }
  31.  
  32. System.out.printf("Total eaten biscuits: %.0fgr.%n", totalBiscuits);
  33. System.out.printf("%.2f%% of the food has been eaten.%n", totalFood / availableFood * 100.0);
  34. System.out.printf("%.2f%% eaten from the dog.%n", dogFood / totalFood * 100.0);
  35. System.out.printf("%.2f%% eaten from the cat.%n", catFood / totalFood * 100.0);
  36. }
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement