This repository was archived by the owner on Mar 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRefereeClass.java
More file actions
214 lines (188 loc) · 5.85 KB
/
RefereeClass.java
File metadata and controls
214 lines (188 loc) · 5.85 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import java.util.*;
/**
* Defines an object representing a single referee
* @author Adam John Campbell Murray
*
*/
public class RefereeClass implements Comparable<RefereeClass>
{
/* Instance variables */
private String refereeID; // consists of initials and a sequence number
private String refereeName; // consists of first and last name (assumed unique)
private String qualification; // e.g. NJB2, IJB1 (highest number is 4)
private int allocatedMatches; // matches allocated to a referee
private String homeLocality; // where the referee lives
private String visitingLocalities; // where the referee is prepared to travel to
private static String whichOrder; // defines the ordering of RefereeClass objects
/**
* Constructor that takes an input string from which
* instance variables are set.
* @param inputString - String containing instance variable information
*/
public RefereeClass(String inputString)
{
// create Scanner for input string
Scanner stringScan = new Scanner(inputString);
// check that there are still tokens to be checked
while(stringScan.hasNext())
{
// initialise instance variables
refereeID = stringScan.next();
refereeName = stringScan.next() + " " + stringScan.next();
qualification = stringScan.next();
allocatedMatches = stringScan.nextInt();
homeLocality = stringScan.next();
visitingLocalities = stringScan.next();
}
// close Scanner for input string
stringScan.close();
}
/**
* Constructor that takes the referee's ID, name,
* qualification, allocated matches, home locality,
* and visiting localities as parameters.
* @param rID - referee's ID
* @param rName - referee's name
* @param qual - referee's qualification
* @param matches - number of matches allocated to referee
* @param hl - referee's home locality
* @param vl - referee's visiting localities
*/
public RefereeClass(String rID, String rName, String qual,
int matches, String hl, String vl)
{
// initialise instance variables
refereeID = rID;
refereeName = rName;
qualification = qual;
allocatedMatches = matches;
homeLocality = hl;
visitingLocalities = vl;
}
/**
* Returns a string formatted for output in the main GUI text area.
* @return guiReportString
*/
public String guiReportString()
{
// formatted string containing information on
// all instance variables
String guiReportString = String.format("%-5s%-20s%-6s%-4d%-10s%-4s", refereeID,
refereeName, qualification, allocatedMatches, homeLocality, visitingLocalities);
return guiReportString;
}
/**
* Returns a string formatted for output in the RefereeDisplayFrame.
* @return individualReportString
*/
public String individualReportString()
{
// formatted string containing information on
// all instance variables
String individualReportString = String.format("Referee ID: %s%nReferee Name: %s%n" +
"Qualification: %s%nAllocated Matches: %d%nHome Locality: %s%n" +
"Visiting Localities: %s%n", refereeID, refereeName, qualification,
allocatedMatches,homeLocality, visitingLocalities);
return individualReportString;
}
/**
* Returns a string formatted for output in the MatchFrame.
* @return matchAllocationsReportString
*/
public String matchAllocationsReportString()
{
// formatted string containing information on
// referee name and number of allocated matches
String matchAllocationsReportString = String.format("%-20s%d", refereeName, allocatedMatches);
return matchAllocationsReportString;
}
/**
* Defines a comparison between RefereeClass objects.
*/
public int compareTo(RefereeClass other)
{
int returnValue = 0;
if (whichOrder.equals("ID"))
{
if (this.getRefereeID().charAt(0) < other.getRefereeID().charAt(0)) // i.e. 'A' and 'K'
returnValue = -1;
else if (this.getRefereeID().charAt(0) == other.getRefereeID().charAt(0)) // i.e. 'A' and 'A'
{
if (this.getRefereeID().charAt(1) < other.getRefereeID().charAt(1)) // i.e. 'AB' and 'AM'
returnValue = -1;
else if (this.getRefereeID().charAt(1) > other.getRefereeID().charAt(1)) // i.e 'AM' and 'AB'
returnValue = 1;
else if (this.getRefereeID().charAt(1) == other.getRefereeID().charAt(1)) // i.e. 'AM' and 'AM'
{
if (this.getRefereeID().charAt(2) < other.getRefereeID().charAt(2)) // i.e. 'AM1' and 'AM2'
returnValue = -1;
else // i.e. 'AM2' and 'AM1'
returnValue = 1;
}
}
else
returnValue = 1;
}
else if (whichOrder.equals("matches"))
{
if (this.getAllocatedMatches() < other.getAllocatedMatches())
returnValue = -1;
else if (this.getAllocatedMatches() == other.getAllocatedMatches())
returnValue = 0;
else
returnValue = 1;
}
return returnValue;
}
/*
* Getters and setters
*/
public String getRefereeID()
{
return refereeID;
}
public String getRefereeName()
{
return refereeName;
}
public String getQualification()
{
return qualification;
}
public int getAllocatedMatches()
{
return allocatedMatches;
}
public String getHomeLocality()
{
return homeLocality;
}
public String getVisitingLocalities()
{
return visitingLocalities;
}
public void setQualification(String qualification)
{
this.qualification = qualification;
}
public void setHomeLocality(String homeLocality)
{
this.homeLocality = homeLocality;
}
public void setVisitingLocalities(String visitingLocalities)
{
this.visitingLocalities = visitingLocalities;
}
public static String getWhichOrder()
{
return whichOrder;
}
public static void setWhichOrder(String whichOrder)
{
RefereeClass.whichOrder = whichOrder;
}
public void setAllocatedMatches(int allocatedMatches)
{
this.allocatedMatches = allocatedMatches;
}
}