Advertisement
psi_mmobile

Untitled

Oct 23rd, 2022
764
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.76 KB | None | 0 0
  1. public class MyClass {
  2.     public static void main(String args[]) {
  3.         double neededExperience = 0.0;
  4.         int numberOfBattles = 0;
  5.         double experienceEarned = 0.0;
  6.         double experienceGainedPerBattle = 0.0;
  7.         double totalExperience = 0.0;
  8.        
  9.         java.util.Scanner scanner = new java.util.Scanner(System.in);
  10.        
  11.         neededExperience = Double.parseDouble(scanner.nextLine());
  12.         numberOfBattles = Integer.parseInt(scanner.nextLine());
  13.        
  14.         for(int battleNumber = 1;battleNumber <= numberOfBattles;battleNumber++) {
  15.             experienceGainedPerBattle = Integer.parseInt(scanner.nextLine());
  16.             if (battleNumber % 3 == 0 && battleNumber % 15 != 0) {
  17.                 totalExperience += (experienceGainedPerBattle * 1.15);
  18.             }
  19.             else if (battleNumber % 5 == 0 && battleNumber % 15 != 0) {
  20.                 totalExperience += (experienceGainedPerBattle * 0.9);
  21.             }
  22.             else if (battleNumber % 15 == 0) {
  23.                 totalExperience += (experienceGainedPerBattle * 1.05);
  24.             } else {
  25.                  totalExperience += experienceGainedPerBattle;
  26.             }
  27.             if (experienceCheck(totalExperience,neededExperience)) {
  28.                 System.out.printf("Player successfully collected his needed experience for %d battles.",battleNumber);
  29.                 break;
  30.             }
  31.         }
  32.         if (!experienceCheck(totalExperience,neededExperience)) {
  33.             System.out.printf("Player was not able to collect, %.2f more needed.",neededExperience - totalExperience);
  34.         }
  35.     }
  36.     public static boolean experienceCheck(double gainedExperience, double neededExperience) {
  37.         return gainedExperience >= neededExperience;
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement