Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyClass {
- public static void main(String args[]) {
- double neededExperience = 0.0;
- int numberOfBattles = 0;
- double experienceEarned = 0.0;
- double experienceGainedPerBattle = 0.0;
- double totalExperience = 0.0;
- java.util.Scanner scanner = new java.util.Scanner(System.in);
- neededExperience = Double.parseDouble(scanner.nextLine());
- numberOfBattles = Integer.parseInt(scanner.nextLine());
- for(int battleNumber = 1;battleNumber <= numberOfBattles;battleNumber++) {
- experienceGainedPerBattle = Integer.parseInt(scanner.nextLine());
- if (battleNumber % 3 == 0 && battleNumber % 15 != 0) {
- totalExperience += (experienceGainedPerBattle * 1.15);
- }
- else if (battleNumber % 5 == 0 && battleNumber % 15 != 0) {
- totalExperience += (experienceGainedPerBattle * 0.9);
- }
- else if (battleNumber % 15 == 0) {
- totalExperience += (experienceGainedPerBattle * 1.05);
- } else {
- totalExperience += experienceGainedPerBattle;
- }
- if (experienceCheck(totalExperience,neededExperience)) {
- System.out.printf("Player successfully collected his needed experience for %d battles.",battleNumber);
- break;
- }
- }
- if (!experienceCheck(totalExperience,neededExperience)) {
- System.out.printf("Player was not able to collect, %.2f more needed.",neededExperience - totalExperience);
- }
- }
- public static boolean experienceCheck(double gainedExperience, double neededExperience) {
- return gainedExperience >= neededExperience;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement