Advertisement
SUni2020

04. Food for Pets

Mar 29th, 2020
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class P4 {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. // Първоначално се чете един ред:
  7. // Брой дни – цяло число в диапазона [1…30]
  8. // Общо количество храна – реално число в диапазона [0.00…10000.00]
  9. // След това за всеки ден се чете:
  10. // o Количество изядена храна от кучето – цяло число в диапазона [10…500]
  11. // o Количество изядена храна от котката – цяло число в диапазона [10…500]
  12.  
  13. int numDays = Integer.parseInt(scanner.nextLine());
  14. double totalFood = Double.parseDouble(scanner.nextLine());
  15. // int eatenFoodDog ;
  16. // int eatenFoodCat ;
  17. /* int startCount = Integer.parseInt(scanner.nextLine());
  18. int stops = Integer.parseInt(scanner.nextLine());
  19.  
  20. for (int stop = 1; stop <= stops ; stop++) {
  21. int outCount = Integer.parseInt(scanner.nextLine());
  22. int inCount = Integer.parseInt(scanner.nextLine());
  23.  
  24. startCount -= outCount;
  25. startCount += inCount; */
  26. int eatenFoodDog = 0;
  27. int eatenFoodCat = 0;
  28. for (int i = 1; i <= numDays; numDays++) {
  29. int eatenFoodDogDaily = Integer.parseInt(scanner.nextLine());
  30. int eatenFoodCatDaily = Integer.parseInt(scanner.nextLine());
  31. eatenFoodDog += eatenFoodDogDaily;
  32. eatenFoodCat += eatenFoodCatDaily;
  33.  
  34. // if (numDays % 3 == 0) {
  35. // double Bonus = 0.10 * (eatenFoodDog + eatenFoodCat);
  36. // double Food = eatenFoodCat + eatenFoodDog + Bonus - Bonus;
  37.  
  38. // 10% от 110 + 40 – 15гр.
  39. // Общо изядена храна: 600гр
  40. // }
  41. double TotalEatenFood = totalFood - (eatenFoodDog + eatenFoodCat);
  42. System.out.printf("Total eaten biscuits: %fgr.", TotalEatenFood);
  43.  
  44. // Общо изядена храна: 600гр.
  45. // Изядена храна от кучето: 510гр, от котката: 90гр.
  46. double PercentageEatenFood = (TotalEatenFood) /1000 * totalFood;
  47. System.out.printf("%.2f of the food has been eaten.%n",PercentageEatenFood);
  48. double PercentageDog = eatenFoodDog * 100 * TotalEatenFood;
  49. System.out.printf("%.2f eaten from the dog.%n", PercentageDog);
  50. double PercentageCat = eatenFoodCat * 100 * TotalEatenFood;
  51. System.out.printf("%.2f eaten from the cat.%n", PercentageCat);
  52.  
  53.  
  54.  
  55.  
  56. }
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement