Advertisement
SotirovG

problem1_MidExam27.03

Mar 4th, 2021
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.43 KB | None | 0 0
  1. package JavaFundamentals.MidExam27_02;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Problem1 {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         double neededExperience = Double.parseDouble(scanner.nextLine());
  10.  
  11.         int battlesCount = Integer.parseInt(scanner.nextLine());
  12.         int battleMore = 0;
  13.         int battleLess = 0;
  14.         int battleInRow15 = 0;
  15.  
  16.         for (int i = 0; i <battlesCount ; i++) {
  17.  
  18.             double experiencedPerBattle=Double.parseDouble(scanner.nextLine());
  19.  
  20.             battleMore ++;
  21.             battleLess ++;
  22.             battleInRow15 ++;
  23.  
  24.             if (battleMore == 3){
  25.                 experiencedPerBattle += (experiencedPerBattle*0.15);
  26.                 battleMore = 0;
  27.             }
  28.             if (battleLess == 5){
  29.                 experiencedPerBattle -= experiencedPerBattle*0.1;
  30.                 battleLess = 0;
  31.             }if (battleInRow15 == 15){
  32.                 experiencedPerBattle += experiencedPerBattle*0.05;
  33.             }
  34.             neededExperience -= experiencedPerBattle;
  35.             if (neededExperience <= 0){
  36.                 System.out.printf("Player successfully collected his needed experience for %d battles.",i+1);
  37.                 return;
  38.             }
  39.  
  40.         }
  41.         System.out.printf("Player was not able to collect the needed experience, %.2f more needed.",neededExperience);
  42.  
  43.     }
  44. }
  45.  
  46.  
  47.  
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement