Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package MidExam;
- import java.util.Scanner;
- public class FirstTask_01 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int days = Integer.parseInt(scanner.nextLine());
- int numberOfPlayers = Integer.parseInt(scanner.nextLine());
- double groupEnergy = Double.parseDouble(scanner.nextLine());
- double waterPerDayForOnePerson = Double.parseDouble(scanner.nextLine());
- double foodPerDayForOnePerson = Double.parseDouble(scanner.nextLine());
- double totalWater = days * 1.0 * numberOfPlayers * waterPerDayForOnePerson;
- double totalFood = days * 1.0 * numberOfPlayers * foodPerDayForOnePerson;
- boolean noEnergy = false;
- for (int i = 1; i <= days ; i++) {
- double lossEnergy = Double.parseDouble(scanner.nextLine());
- groupEnergy = groupEnergy - lossEnergy;
- if (groupEnergy <= 0){
- noEnergy = true;
- break;
- }
- if (i % 2 == 0){
- groupEnergy = groupEnergy + (groupEnergy * 0.05);
- totalWater = totalWater - (totalWater * 0.3);
- }
- if (i % 3 == 0){
- totalFood = totalFood - (totalFood / numberOfPlayers);
- groupEnergy = groupEnergy + (groupEnergy * 0.1);
- }
- }
- if (noEnergy){
- System.out.printf("You will run out of energy. You will be left with %.2f food and %.2f water.%n", 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