SHARE
TWEET

Experience Gaining

a guest Feb 28th, 2020 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
  8.         double neededExperience = Double.parseDouble(scanner.nextLine());
  9.         int battles = Integer.parseInt(scanner.nextLine());
  10.  
  11.      
  12.  
  13.         double collectedExperience = 0;
  14.  
  15.         for (int i = 1; i <=battles ; i++) {
  16.  
  17.             double expiriencePerBattle = Double.parseDouble(scanner.nextLine());
  18.  
  19.                 if (i % 3 == 0){
  20.                     collectedExperience += expiriencePerBattle*1.15;
  21.                 }else if (i % 5 == 0 ){
  22.  
  23.                     collectedExperience += expiriencePerBattle*0.9;
  24.                 }else {
  25.                     collectedExperience += expiriencePerBattle;
  26.                 }
  27.  
  28.                 if (collectedExperience >= neededExperience){
  29.  
  30.                  
  31.                     System.out.printf("Player successfully collected his needed experience for %d battles.",i);
  32.                     break;
  33.             }
  34.  
  35.         }
  36.         if (neededExperience-collectedExperience > 0) {
  37.  
  38.             double moreNeededExperince = neededExperience - collectedExperience;
  39.  
  40.             System.out.printf("Player was not able to collect the needed experience, %.2f more needed.", moreNeededExperince);
  41.         }
  42.     }
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top