Advertisement
ilianrusev

Technology Fundamentals Mid Exam - 10 March 2019 Group 2 - 1

Apr 15th, 2019
162
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7. public static void main(String[] args) {
  8.  
  9. Scanner scanner = new Scanner(System.in);
  10.  
  11. int days = Integer.parseInt(scanner.nextLine());
  12. int numberOfPlayers = Integer.parseInt(scanner.nextLine());
  13. double energy = Double.parseDouble(scanner.nextLine());
  14. double waterPerDay = Double.parseDouble(scanner.nextLine());
  15. double foodPerDay = Double.parseDouble(scanner.nextLine());
  16.  
  17. double totalFood = numberOfPlayers * foodPerDay * days;
  18. double totalWater = numberOfPlayers * waterPerDay * days;
  19.  
  20. System.out.println();
  21.  
  22.  
  23. for (int i = 1; i <= days; i++) {
  24. double dayEnergyLoss = Double.parseDouble(scanner.nextLine());
  25.  
  26. energy -= dayEnergyLoss;
  27. if (energy <= 0){
  28. System.out.printf("You will run out of energy. " +
  29. "You will be left with %.2f food and %.2f water.",totalFood,totalWater);
  30. return;
  31. }
  32.  
  33. if (i % 2 == 0){
  34. energy = energy + (energy * 0.05);
  35. totalWater = totalWater - (totalWater * 0.3);
  36. }
  37.  
  38. if (i % 3 == 0){
  39. totalFood = totalFood - (totalFood / numberOfPlayers);
  40. energy = energy + (energy * 0.10);
  41. }
  42. }
  43. System.out.printf("You are ready for the quest. " +
  44. "You will be left with - %.2f energy!\n",energy);
  45. }
  46. }
Advertisement
RAW Paste Data Copied
Advertisement