Advertisement
lifesaver800

Experience Gaining

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