Advertisement
veronikaaa86

01. The Hunting Games

Oct 25th, 2021
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. package exam;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P01TheHuntingGames {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. int days = Integer.parseInt(scanner.nextLine());
  10. int players = Integer.parseInt(scanner.nextLine());
  11. double groupEnergy = Double.parseDouble(scanner.nextLine());
  12. double waterPerDayPerPerson = Double.parseDouble(scanner.nextLine());
  13. double foodPerDayPerPerson = Double.parseDouble(scanner.nextLine());
  14.  
  15. double totalWater = days * 1.0 * players * waterPerDayPerPerson;
  16. double totalFood = days * 1.0 * players * foodPerDayPerPerson;
  17.  
  18. for (int i = 1; i <= days; i++) {
  19. double energyLoss = Double.parseDouble(scanner.nextLine());
  20.  
  21. groupEnergy = groupEnergy - energyLoss;
  22.  
  23. if (groupEnergy <= 0) {
  24. break;
  25. }
  26.  
  27. if (i % 2 == 0) {
  28. groupEnergy = groupEnergy + (groupEnergy * 0.05);
  29. totalWater = totalWater - (totalWater * 0.30);
  30. }
  31.  
  32. if (i % 3 == 0) {
  33. groupEnergy = groupEnergy + (groupEnergy * 0.10);
  34. totalFood = totalFood - (totalFood / players);
  35. }
  36.  
  37. }
  38.  
  39. if (groupEnergy <= 0) {
  40. System.out.printf("You will run out of energy. You will be left with %.2f food and %.2f water.", totalFood, totalWater);
  41. } else {
  42. System.out.printf("You are ready for the quest. You will be left with - %.2f energy!", groupEnergy);
  43. }
  44. }
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement