-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
67 lines (59 loc) · 2.06 KB
/
Copy pathPlayer.java
File metadata and controls
67 lines (59 loc) · 2.06 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
public class Player {
private final String username;
private double accuracy;
private int totalGuesses, cryptogramsPlayed, cryptogramsCompleted, totalCorrectGuesses;
public Player(String username, int totalGuesses, int totalCorrectGuesses, int cryptogramsPlayed, int cryptogramsCompleted) {
this.username = username.toUpperCase();
this.totalGuesses = totalGuesses;
this.cryptogramsPlayed = cryptogramsPlayed;
this.totalCorrectGuesses = totalCorrectGuesses;
this.cryptogramsCompleted = cryptogramsCompleted;
}
public Player(String username) {
// TODO: meaningful default savedGame value
this(username.toUpperCase(), 0, 0, 0, 0);
}
public void incrementTotalGuesses() {
totalGuesses += 1;
}
public void incrementCryptogramsPlayed() {
cryptogramsPlayed += 1;
}
public void incrementCryptogramsCompleted() {
cryptogramsCompleted += 1;
}
public void incrementTotalCorrectGuesses() {
totalCorrectGuesses += 1;
}
public void updateAccuracy() {
if (cryptogramsPlayed > 0) {
accuracy = ((double) totalCorrectGuesses / (double) totalGuesses) * 100;
} else {
accuracy = 0;
}
}
public String getUsername() {
return username.toUpperCase();
}
public int getTotalGuesses() {
return totalGuesses;
}
public int getTotalCorrectGuesses() {
return totalCorrectGuesses;
}
public int getCryptogramsPlayed() {
return cryptogramsPlayed;
}
public int getCryptogramsCompleted() {
return cryptogramsCompleted;
}
public double getAccuracy(){return accuracy;}
@Override
public String toString() {
return "Username: " + username + ",\n" +
"Total Guesses: " + totalGuesses + ",\n" +
"Total Correct Guesses: " + totalCorrectGuesses + ",\n" +
"Cryptograms Played: " + cryptogramsPlayed + ",\n" +
"Cryptograms Completed: " + cryptogramsCompleted + ",\n";
}
}