-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudentFactory.java
80 lines (69 loc) · 2.22 KB
/
StudentFactory.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
package com.B5015845.CSC8002.Coursework;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* This class is a factory to create unique instances of different types of students.
* This code is adapted from the CSC8002 lecture slides on object factories.
* @author Arianna Esposito
*
*/
public final class StudentFactory {
private static final Map<StudentID, Student> UG_STUDENTS = new HashMap<StudentID, Student>();
private static final Map<StudentID, Student> PGT_STUDENTS = new HashMap<StudentID, Student>();
private static final Map<StudentID, Student> PGR_STUDENTS = new HashMap<StudentID, Student>();
/**
* This method is the only way to create students that are registered in the university system.
* @param studentName
* @param dob
* @param studentType
* @return unique instance of a Student
*/
public final static Student getInstance(Name studentName, Date dob, StudentType studentType)
{
Student s;
ResearchStudent rs;
StudentType st = studentType;
switch (st) {
case UG: studentType = StudentType.UG;
s = new UG(studentName, dob);
UG_STUDENTS.put(s.getStudentID(), s);
return s;
case PGT: studentType = StudentType.PGT;
s = new PGT(studentName, dob);
PGT_STUDENTS.put(s.getStudentID(), s);
return s;
case PGR: studentType = StudentType.PGR;
Supervisor sup = null;
rs = new PGR(studentName, dob, sup);
PGR_STUDENTS.put(rs.getStudentID(), rs);
return rs;
default:
throw new IllegalArgumentException("Students can only be UG, PGT or PGR");
}
}
/**
* Retrieves all undergraduate students in the system
* @return all undergraduate students
*/
public static Map<StudentID, Student> getUGs()
{
return UG_STUDENTS;
}
/**
* Retrieves all postgraduate taught students in the system
* @return all postgraduate taught students
*/
public static Map<StudentID, Student> getPGTs()
{
return PGT_STUDENTS;
}
/**
* Retrieves all postgraduate research students in the system
* @return all postgraduate research students
*/
public static Map<StudentID, Student> getPGRs()
{
return PGR_STUDENTS;
}
}