-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUser.java
107 lines (86 loc) · 2.14 KB
/
User.java
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import java.util.Set;
import java.util.HashSet;
public class User {
/* private variables */
/*
* A list of this user's coaches.
*/
private Set<User> coaches;
/*
* A list of this user's students.
*/
private Set<User> students;
/*
* The most up-to-date version the user currently owns.
*/
private int version;
/*
* The number of infected students this user has
*/
private int numInfectedStudents;
/*
* the unique string identifier for this user
*/
private String name;
/* Constructor
* Allocate memory for lists.
* Assign version to passed-in parameter.
*/
public User(String name, int version) {
this.coaches = new HashSet<User>();
this.students = new HashSet<User>();
this.version = version;
this.name = name.toLowerCase();
}
/* Default Constructor
* In case we don't immediately know what the user's version is
*/
public User(String name) {
this.coaches = new HashSet<User>();
this.students = new HashSet<User>();
this.version = 0;
this.name = name.toLowerCase();
}
public void setVersion(int version) {
this.version = version;
}
public int getVersion() {
return version;
}
public String getName() {
return name;
}
public Set<User> getCoaches() {
return coaches;
}
public Set<User> getStudents() {
return students;
}
public boolean addCoach(User coach) {
return coaches.add(coach);
}
public boolean addStudent(User student) {
return students.add(student);
}
// TODO decide whether you will store in a variable,
// or will iterate to find...
public void incrementInfectedStudents() {
numInfectedStudents++;
}
public void setNumInfectedStudents(int value) {
numInfectedStudents = value;
}
public int getNumInfectedStudents() {
return numInfectedStudents;
}
// Brute force, finding number of students infected
public int getNumberOfInfectedStudents(int latest_version) {
int numInfected = 0;
for(User user : students) {
if(user.getVersion() == latest_version) {
numInfected++;
}
}
return numInfected;
}
}