-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParticipant.java
More file actions
89 lines (74 loc) · 1.88 KB
/
Participant.java
File metadata and controls
89 lines (74 loc) · 1.88 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package speedmatch;
/**
*
* @author Jochen
*/
public class Participant implements java.io.Serializable{
private String f_name;
private String l_name;
private int gender;
private int id;
private int[] match; // Integer-Array storing IDs of people liked by participant
private int counter = 0;
// Constructor
public Participant(String fname, String lname, int gnd, int nr, int matches){
this.f_name = fname;
this.l_name = lname;
this.gender = gnd;
this.id = nr;
this.match = new int[matches];
for(int i=0; i<this.match.length; i++) {
this.match[i] = -1;
}
}
// Adds a single like. Throws an exception, if the maximum number of likes
// is being exceeded.
public boolean addMatch(int i) throws MatchException{
if(counter<match.length){
this.match[counter] = i;
this.counter++;
return true;
}
else{
throw new MatchException("You exceeded the maximum number of Likes for Participant "+ this.getFullName());
}
}
// Adds an entire Array of liked IDs at once. Throws an exception if length
// of array is greater than the maximum number of likes.
public void addMatch(int[] ia) throws MatchException{
if(ia.length==match.length) {
this.match = ia;
}
else if(ia.length<this.match.length) {
for(int j=0; j<ia.length; j++) {
this.match[j] = ia[j];
}
}
else {
throw new MatchException("Your Array of Likes is too long for participant "+this.getFullName());
}
}
// Get-Methods for private Variables
public int getID(){
return this.id;
}
public String getFirstName(){
return this.f_name;
}
public String getLastName(){
return this.l_name;
}
public String getFullName(){
String tmp = this.f_name + " " +this.l_name;
return tmp;
}
public int[] getMatches(){
return this.match;
}
public String toString(){
return this.id+": "+this.f_name+" "+this.l_name;
}
public int getGender() {
return this.gender;
}
}