Advertisement
Tsuki11

ExperienceGaining

Feb 24th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.39 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Task_1_ExperienceGaining {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         double experienceGoal = Double.parseDouble(scan.nextLine());
  8.         int battlesCount = Integer.parseInt(scan.nextLine());
  9.  
  10.         boolean hasExperience = false;
  11.  
  12.         double earnedExperience = 0;
  13.         int countBattles = 0;
  14.  
  15.         while (countBattles < battlesCount){
  16.             countBattles++;
  17.             double experiencePerGame = Double.parseDouble(scan.nextLine());
  18.  
  19.             if(countBattles % 3 == 0){
  20.                 earnedExperience+=experiencePerGame * 1.15;
  21.             }else if(countBattles % 5 == 0){
  22.                 earnedExperience+=experiencePerGame * 0.90;
  23.             }else{
  24.                 earnedExperience+=experiencePerGame;
  25.             }
  26.  
  27.             if(earnedExperience >= experienceGoal){
  28.                 hasExperience = true;
  29.                 break ;
  30.             }
  31.  
  32.  
  33.         }
  34.  
  35.         if(hasExperience){
  36.             System.out.printf("Player successfully collected his needed experience for %d battles.",countBattles);
  37.         }else {
  38.             double experienceNeeded = experienceGoal - earnedExperience;
  39.             System.out.printf("Player was not able to collect the needed experience, " +
  40.                     "%.2f more needed.",experienceNeeded);
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement