Skip to content

Commit ec7922b

Browse files
author
khalil2535
committed
Using SortedArray in ScoreBoard
1 parent 811737e commit ec7922b

File tree

3 files changed

+60
-94
lines changed

3 files changed

+60
-94
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package DataStructures.Arrays.SortedArray.Implementaion;
2+
3+
import DataStructures.Arrays.SortedArray.SortedArray;
4+
import java.util.Random;
5+
6+
public class ScoreBoard {
7+
8+
public static void main(String[] args) {
9+
Random ran = new Random();
10+
ScoreBoard highScore = new ScoreBoard(10);
11+
highScore.addScore(new ScoreRecord(ran.nextInt(500), "player1"));
12+
highScore.addScore(new ScoreRecord(ran.nextInt(500), "player2"));
13+
highScore.addScore(new ScoreRecord(ran.nextInt(500), "player3"));
14+
highScore.addScore(new ScoreRecord(ran.nextInt(500), "player4"));
15+
highScore.addScore(new ScoreRecord(ran.nextInt(500), "player5"));
16+
highScore.addScore(new ScoreRecord(ran.nextInt(500), "player6"));
17+
highScore.addScore(new ScoreRecord(ran.nextInt(500), "player13"));
18+
highScore.addScore(new ScoreRecord(ran.nextInt(500), "player14"));
19+
highScore.addScore(new ScoreRecord(ran.nextInt(500), "player7"));
20+
highScore.addScore(new ScoreRecord(ran.nextInt(500), "player8"));
21+
highScore.addScore(new ScoreRecord(ran.nextInt(500), "player9"));
22+
highScore.addScore(new ScoreRecord(ran.nextInt(500), "player10"));
23+
highScore.addScore(new ScoreRecord(ran.nextInt(500), "player11"));
24+
highScore.addScore(new ScoreRecord(ran.nextInt(500), "player12"));
25+
System.out.println(highScore);
26+
}
27+
28+
private SortedArray<ScoreRecord> scoreRecordsArray;
29+
30+
public ScoreBoard(int capacity) {
31+
scoreRecordsArray = new SortedArray<>(capacity);
32+
}
33+
34+
@Override
35+
public String toString() {
36+
return scoreRecordsArray.toString();
37+
}
38+
39+
public boolean addScore(ScoreRecord record) {
40+
return scoreRecordsArray.add(record);
41+
}
42+
43+
public boolean removeScore(ScoreRecord record) {
44+
return scoreRecordsArray.remove(record);
45+
}
46+
47+
/**
48+
* @return the scoreRecordsArray
49+
*/
50+
public ScoreRecord[] getScoreRecordsArray() {
51+
return scoreRecordsArray.getArray();
52+
}
53+
54+
}

DataStructures/Arrays/SortedArray/Implementaion/ScoreRecord.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package DataStructures.Arrays.SortedArray.Implementaion;
22

3-
public class ScoreRecord {
3+
public class ScoreRecord implements Comparable<ScoreRecord> {
44

55
private int score;
66
private String name;
@@ -29,4 +29,9 @@ public String getName() {
2929
return name;
3030
}
3131

32+
@Override
33+
public int compareTo(ScoreRecord o) {
34+
return this.score - o.score;
35+
}
36+
3237
}

DataStructures/Arrays/SortedArray/Implementaion/Scoreboard.java

Lines changed: 0 additions & 93 deletions
This file was deleted.

0 commit comments

Comments
 (0)