meteor4o

JF-MidExam-10March-Group2-01.TheHuntingGames

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