Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package exam;
- import java.util.Scanner;
- public class P01TheHuntingGames {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int days = Integer.parseInt(scanner.nextLine());
- int players = Integer.parseInt(scanner.nextLine());
- double groupEnergy = Double.parseDouble(scanner.nextLine());
- double waterPerDayPerPerson = Double.parseDouble(scanner.nextLine());
- double foodPerDayPerPerson = Double.parseDouble(scanner.nextLine());
- double totalWater = days * 1.0 * players * waterPerDayPerPerson;
- double totalFood = days * 1.0 * players * foodPerDayPerPerson;
- for (int i = 1; i <= days; i++) {
- double energyLoss = Double.parseDouble(scanner.nextLine());
- groupEnergy = groupEnergy - energyLoss;
- if (groupEnergy <= 0) {
- break;
- }
- if (i % 2 == 0) {
- groupEnergy = groupEnergy + (groupEnergy * 0.05);
- totalWater = totalWater - (totalWater * 0.30);
- }
- if (i % 3 == 0) {
- groupEnergy = groupEnergy + (groupEnergy * 0.10);
- totalFood = totalFood - (totalFood / players);
- }
- }
- if (groupEnergy <= 0) {
- System.out.printf("You will run out of energy. You will be left with %.2f food and %.2f water.", totalFood, totalWater);
- } else {
- System.out.printf("You are ready for the quest. You will be left with - %.2f energy!", groupEnergy);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement