Roadstar3

Experience Gaining Mid - Exams Fundamentals

Feb 26th, 2020
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 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.         double amountExperience = Double.parseDouble(scanner.nextLine());
  7.         int numOfBattles = Integer.parseInt(scanner.nextLine());
  8.        
  9.         int count = 0;
  10.         int countOfBattles = 0;
  11.         double sum = 0;
  12.        
  13.         for (int i = 0; i < numOfBattles; i++) {
  14.             double experience = Double.parseDouble(scanner.nextLine());
  15.             count++;
  16.             countOfBattles++;
  17.  
  18.             if (count == 3) {
  19.                 sum += experience + (experience * 0.15);
  20.             } else if (count == 5) {
  21.                 sum += experience - (experience * 0.10);
  22.                 count = 0;
  23.             }else {
  24.                 sum += experience;
  25.             }
  26.             if (sum >= amountExperience) {
  27.                 System.out.printf("Player successfully collected his needed experience for %d battles.", countOfBattles);
  28.                 return;
  29.             }
  30.         }
  31.         double diff = amountExperience - sum;
  32.         System.out.printf("Player was not able to collect the needed experience, %.2f more needed.", diff);
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment