-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
76 lines (53 loc) · 2.25 KB
/
Main.java
File metadata and controls
76 lines (53 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package academy.learnprogramming;
public class Main {
public static void main(String[] args) {
boolean gameOver = true;
int score = 800;
int levelCompleted = 5;
int bonus = 100;
int highScore = calculateScore(gameOver, score, levelCompleted, bonus);
System.out.println("Your final score was " + highScore);
score = 10000;
levelCompleted = 8;
bonus = 200;
highScore = calculateScore(gameOver, score, levelCompleted, bonus);
System.out.println("Your final score was " + highScore);
int highScorePosition = calculateHighScorePosition(1500);
displayHighScorePosition("Tim", highScorePosition);
highScorePosition = calculateHighScorePosition(900);
displayHighScorePosition("Bob", highScorePosition);
highScorePosition = calculateHighScorePosition(400);
displayHighScorePosition("Percy", highScorePosition);
highScorePosition = calculateHighScorePosition(50);
displayHighScorePosition("Gilbert", highScorePosition);
highScorePosition = calculateHighScorePosition(1000);
displayHighScorePosition("Louise", highScorePosition);
highScorePosition = calculateHighScorePosition(500);
displayHighScorePosition("Carol", highScorePosition);
highScorePosition = calculateHighScorePosition(100);
displayHighScorePosition("Frank", highScorePosition);
}
public static void displayHighScorePosition(String playerName, int highScorePosition) {
System.out.println(playerName+" managed to get into position "
+ highScorePosition + " on the high score table");
}
public static int calculateHighScorePosition(int playerScore) {
int position = 4;
if(playerScore >= 1000) {
return 1;
} else if(playerScore >= 500) {
return 2;
} else if(playerScore >= 100) {
return 3;
}
return position;
}
public static int calculateScore(boolean gameOver,int score, int levelCompleted, int bonus) {
if(gameOver) {
int finalScore = score + (levelCompleted * bonus);
finalScore += 2000;
return finalScore;
}
return -1;
}
}