Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Pet {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. int daysCount=Integer.parseInt(scanner.nextLine());
  7. double totalFoodQuantity=Double.parseDouble(scanner.nextLine());
  8. double biscuitsCountTotal=0;
  9. double totalFoodEaten=0;
  10. double dogPercent=0;
  11. double catPercent=0;
  12.  
  13. double dogAteTotal = 0;
  14. double catAteTotal = 0;
  15.  
  16. for (int i=1; i<=daysCount;i++){
  17. double biscuitsCount = 0;
  18. double dogAte=Double.parseDouble(scanner.nextLine());
  19. double catAte=Double.parseDouble(scanner.nextLine());
  20.  
  21. if (i%3==0){
  22. biscuitsCount=0.1*(dogAte+catAte);
  23. biscuitsCountTotal += biscuitsCount;
  24. }
  25.  
  26. totalFoodEaten=totalFoodEaten+dogAte+catAte;
  27. dogAteTotal += dogAte;
  28. catAteTotal += catAte;
  29.  
  30. }
  31.  
  32. double percentFood=(totalFoodEaten/totalFoodQuantity) * 100;
  33.  
  34. dogPercent=(dogAteTotal/totalFoodEaten) * 100;
  35. catPercent=(catAteTotal/totalFoodEaten) * 100;
  36.  
  37. System.out.printf("Total eaten biscuits: %dgr.\n", Math.round(biscuitsCountTotal));
  38. System.out.printf("%.2f%% of the food has been eaten.\n",percentFood);
  39. System.out.printf("%.2f%% eaten from the dog.\n", dogPercent);
  40. System.out.printf("%.2f%% eaten from the cat.\n", catPercent);
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement