Last active
June 14, 2021 07:11
-
-
Save tbelmega/e942c78867712ea446b445ffdd3cf8da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.time.LocalDate; | |
public class Game { | |
static HighscoreEntry[] highscore = new HighscoreEntry[10]; | |
public static void main(String[] args) { | |
addHighscore("Bob", 500); | |
addHighscore("Kevin", 440); | |
addHighscore("Dave", 600); | |
print(highscore); | |
} | |
private static void addHighscore(String playerName, int score) { | |
for (int i = 0; i < highscore.length; i++) { | |
if (highscore[i] == null) { | |
HighscoreEntry newHighscoreEntry = | |
new HighscoreEntry( | |
playerName, | |
score, | |
LocalDate.now() | |
); | |
highscore[i] = newHighscoreEntry; | |
break; | |
} | |
} | |
} | |
private static void print(HighscoreEntry[] highscore) { | |
System.out.println("#################"); | |
System.out.println("### HIGHSCORE ###"); | |
System.out.println("#################"); | |
for (int i = 0; i < highscore.length; i++) { | |
// System.out.println(highscore[i].getPlayerName() + " " | |
// + highscore[i].getScore()); | |
highscore[i].print(); | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.time.LocalDate; | |
public class HighscoreEntry { | |
private String playerName; | |
private int score; | |
private LocalDate date; | |
/** | |
* Konstruktor, der die folgenden Werte setzt: | |
* @param playerName der spielwename | |
* @param score die punktzahl | |
* @param date datum des spiels | |
*/ | |
public HighscoreEntry(String playerName, int score, LocalDate date) { | |
this.playerName = playerName; | |
this.score = score; | |
this.date = date; | |
} | |
/** | |
* Get the playername | |
* @return the playername | |
*/ | |
public String getPlayerName() { | |
return playerName; | |
} | |
public int getScore() { | |
return score; | |
} | |
public LocalDate getDate() { | |
return date; | |
} | |
public void print() { | |
System.out.println(playerName + " " + score); | |
} | |
public static void main(String[] args) { | |
new HighscoreEntry("Bob", 600, LocalDate.now()).print(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment