Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class TankTask {
  4. public static void main(String[] args) {
  5. Scanner scan = new Scanner(System.in);
  6.  
  7. double experience = Double.parseDouble(scan.nextLine());
  8. int countOfBattles = Integer.parseInt(scan.nextLine());
  9.  
  10. int counter =0;
  11.  
  12. double earnedXp =0;
  13.  
  14.  
  15. for (int i = 1; i <=countOfBattles ; i++) {
  16.  
  17.  
  18. if(earnedXp>=experience) {
  19. System.out.printf("Player successfully collected his needed experience for %d battles.",counter);
  20. return;
  21. }
  22. double xpPerBattle = Double.parseDouble(scan.nextLine());
  23.  
  24.  
  25. if(i%3!=0&&i%5!=0){
  26. earnedXp+=xpPerBattle;
  27. counter++;
  28.  
  29. }else if(i%3==0){
  30. earnedXp+=xpPerBattle*1.15;
  31. counter++;
  32.  
  33.  
  34. }else {
  35. earnedXp+=xpPerBattle*0.9;
  36. counter++;
  37. }
  38. }
  39.  
  40. if(experience>earnedXp){
  41. double diff = experience-earnedXp;
  42. System.out.printf("Player was not able to collect the needed experience, %.2f more needed.",diff);
  43. }else if(earnedXp>experience) {
  44. System.out.printf("Player successfully collected his needed experience for %d battles.",counter);
  45.  
  46. }
  47.  
  48.  
  49.  
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement