FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java-algorithims/ScoreBoard.java at main · faraimtb/java-algorithims · GitHub
This repository was archived by the owner on Dec 7, 2024. It is now read-only.
faraimtb
/
java-algorithims
Public archive
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
java-algorithims
/
ScoreBoard.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
51 lines (40 loc) · 1.39 KB
Breadcrumbs
java-algorithims
/
ScoreBoard.java
Copy path
File metadata and controls
51 lines (40 loc) · 1.39 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package
com
.
ematrix
;
public
class
ScoreBoard
{
private
int
scoreEntries
=
0
;
private
GameEntry
[]
board
;
public
ScoreBoard
(
int
boardSize
){
board
=
new
GameEntry
[
boardSize
];
}
public
GameEntry
[]
getBoard
() {
return
board
;
}
public
void
addScoreToBoard
(
GameEntry
newScoreEntry
) {
int
newScore
=
newScoreEntry
.
getPlayerScore
( );
if
(
scoreEntries
<
board
.
length
||
newScore
>
board
[
scoreEntries
-
1
].
getPlayerScore
( )) {
if
(
scoreEntries
<
board
.
length
)
// no score drops from the board
scoreEntries
++;
int
j
=
scoreEntries
-
1
;
while
(
j
>
0
&&
this
.
board
[
j
-
1
].
getPlayerScore
() <
newScore
) {
board
[
j
] =
this
.
board
[
j
-
1
];
// shift entry from j-1 to j
j
--;
// and decrement j
}
board
[
j
] =
newScoreEntry
;
}
}
public
GameEntry
removeScoreToBoard
(
int
scoreIndex
)
throws
IndexOutOfBoundsException
{
if
(
scoreIndex
>
this
.
scoreEntries
-
1
){
throw
new
IndexOutOfBoundsException
(
"Invalid index: "
+
scoreIndex
);
}
int
j
=
scoreIndex
;
GameEntry
temp
=
this
.
board
[
j
];
for
(;
j
<
scoreEntries
-
1
;
j
++){
this
.
board
[
j
] =
this
.
board
[
j
+
1
];
}
this
.
board
[
j
]=
null
;
scoreEntries
--;
return
temp
;
}
public
int
getScoreEntries
() {
return
scoreEntries
;
}
}
Back
|
FazBrowse Home
|
New Git URL