Advertisement
Guest User

01. Experience Gaining

a guest
Nov 10th, 2019
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.43 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Group2 {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         double neededExperience = scanner.nextDouble();
  10.         int countOfBattles = scanner.nextInt();
  11.  
  12.         double myExperience = 0.0;
  13.  
  14.  
  15.         int num = 0;
  16.  
  17.         for (int i = 1; i <= countOfBattles; i++) {
  18.  
  19.                 if(myExperience>=neededExperience){
  20.                     System.out.printf("Player successfully collected his needed experience for %d battles.",num );
  21.                     return;
  22.                 }
  23.             int command = scanner.nextInt();
  24.  
  25.                 if (i%3 != 0 && i%5 != 0 ) {
  26.                 myExperience +=command;
  27.                 num++;
  28.             }
  29.  
  30.                 if(i%3 ==0) {
  31.                     myExperience += (command + 0.15 * command);
  32.                     num++;
  33.                 }
  34.  
  35.                 if(i%5==0){
  36.                     myExperience += (command - 0.10*command);
  37.                     num++;
  38.                 }
  39.  
  40.         }
  41.  
  42.         if(myExperience<neededExperience){
  43.             double result = neededExperience-myExperience;
  44.             System.out.printf("Player was not able to collect the needed experience, %.2f more needed.", result);
  45.         }
  46.         else {
  47.             System.out.printf("Player successfully collected his needed experience for %d battles.",num );
  48.         }
  49.  
  50.  
  51.  
  52.  
  53.  
  54.     }
  55.  
  56.  
  57.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement