-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathPlayer.java
More file actions
52 lines (39 loc) · 1.06 KB
/
Player.java
File metadata and controls
52 lines (39 loc) · 1.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
package co.ppg2.model;
import java.io.Serializable;
public class Player implements Serializable {
private String username;
private int wins;
private int losses;
public Player(String username) {
setUsername(username);
this.username = username;
this.wins = 0;
this.losses = 0;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
//added to make sure username is not empty
if (username == null || username.trim().isEmpty()) {
throw new IllegalArgumentException("Username can't be empty. Please enter a valid username.");
}
this.username = username;
}
public int getWins() {
return wins;
}
public int getLosses() {
return losses;
}
public void incrementWins() {
this.wins++;
}
public void incrementLosses() {
this.losses++;
}
@Override
public String toString() {
return username + " - Wins: " + wins + ", Losses: " + losses;
}
}