Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
83 lines (60 loc) · 2.37 KB
/
Copy pathMain.java
File metadata and controls
83 lines (60 loc) · 2.37 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
77
78
79
80
81
82
83
package com.JunBau;
public class Main {
public static void main(String[] args) {
boolean gameOver = true;
int score = 1000;
int levelCompleted = 5;
int bonus = 100;
String playerName = "bob";
int highScore = calculateScore(gameOver, score, levelCompleted, bonus);
System.out.println("Your final score was: " + highScore);
highScore = calculateHighScorePosition(highScore);
displayHighScorePosition(playerName,highScore);
score = 500;
levelCompleted = 2;
bonus = 200;
playerName = "aidan";
highScore = calculateScore(gameOver, score, levelCompleted, bonus);
System.out.println("Your final score was: " + highScore);
highScore = calculateHighScorePosition(highScore);
displayHighScorePosition(playerName,highScore);
score = 200;
levelCompleted = 1;
bonus = 200;
playerName = "alex";
highScore = calculateScore(gameOver, score, levelCompleted, bonus);
System.out.println("Your final score was: " + highScore);
highScore = calculateHighScorePosition(highScore);
displayHighScorePosition(playerName,highScore);
score = 10;
levelCompleted = 2;
bonus = 20;
playerName = "miguel";
highScore = calculateScore(gameOver, score, levelCompleted, bonus);
System.out.println("Your final score was: " + highScore);
highScore = calculateHighScorePosition(highScore);
displayHighScorePosition(playerName,highScore);
}
public static int calculateScore(boolean gameOver, int score, int levelCompleted, int bonus) {
if (gameOver) {
int finalScore = score + (levelCompleted * bonus);
return finalScore;
} else {
return -1;
}
}
public static void displayHighScorePosition(String playersName, int position) {
System.out.println(playersName + " managed to get into position: " + position + " on the high score table.");
}
public static int calculateHighScorePosition(int playerScore) {
if(playerScore >= 1000) {
return 1;
} else if (playerScore >= 500 && playerScore < 1000) {
return 2;
} else if (playerScore >= 100 && playerScore < 500) {
return 3;
} else {
return 4;
}
}
}