This repository has been archived by the owner on Jun 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Student.java
155 lines (138 loc) · 4.41 KB
/
Student.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
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
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
/**
* Represents a student in the school.
* A student can be enrolled in many courses.
* @author Group3
* @version 1.0
*/
public class Student implements Serializable {
/**
* Name of this student.
*/
private String name;
/**
* Matric number of this student.
*/
private String matricNo;
/**
* School of this student.
*/
private String school;
/**
* Gender of this student.
*/
private String gender;
/**
* An array of <code>Record</code> object.
* Each <code>Record</code> object contains a 'student-course'pair and this student's mark of a course.
*/
private ArrayList<Record> recordList;
/**
* A dictionary which stores all courses taken by this student.
* key: coursecode, value: index of a course
*/
private HashMap<String, Integer> allCourses;
/**
* Number of courses taken by this student.
*/
private int couseCount;
/**
* <code>Student</code> constructor.
* Creates a new student with given name, matricNo, school and gender.
* @param name name of this student
* @param matricNo matricnumber of this student
* @param school shcool of this student
* @param gender gender of this student
*/
public Student(String name, String matricNo, String school, int gender) {
this.name = name;
this.matricNo = matricNo;
this.school = school;
if(gender == 1)
this.gender = "Male";
else if(gender == 2)
this.gender = "Female";
else if(gender == 3)
this.gender = "Genderqueer";
recordList = new ArrayList<>();
allCourses = new HashMap<>();
couseCount = 0;
}
/**
* Adds a record of this student to <code>recordList</code>.
* The <code>Record</code> object contains a 'student-course'pair and this student's mark of a course.
* Adds the corresponding course into the course list of this student.
* @param record the <code>Record</code> object to be added
*/
public void addRecord(Record record) {
recordList.add(record);
allCourses.put(record.getCourse().getName(), couseCount);
couseCount++;
}
/**
* Checks if this student registers the course with given coursecode.
* @param courseCode the coursecode of the course being checked
* @return a boolean value
* true if this student registers the given course
* false if this student dose not register the given course
*/
public boolean checkRegistered(String courseCode){
if(allCourses.containsKey(courseCode)){
return true;
}
else return false;
}
/**
* Prints the transcript of this student.
* Inclusive of this student's personal information,
* overall mark and individual mark of each component of all courses taken by this student.
*/
public void printTranscript() {
System.out.format("Name: %s\nMatric Number: %s\nGender: %s\n", name, matricNo, gender);
System.out.println("Printing marks for all course");
System.out.println();
for (Record record : recordList) {
System.out.format("%20s | %f\n", record.getCourse().getName(), record.getOverallMark());
record.printMarks();
}
System.out.println();
}
/**
* Gets the name of this student.
* @return the name of this student
*/
public String getName() {
return this.name;
}
/**
* Gets the matric number of this student.
* @return the matric number of this student
*/
public String getMatricNo() {
return this.matricNo;
}
/**
* Gets the school of this student.
* @return the school of this student
*/
public String getSchool() {
return this.school;
}
/**
* Gets the gender of this student.
* @return the gender of this student
*/
public String getGender() {
return this.gender;
}
/**
* Gets an array of <code>Record</code> object.
* Each Record contains a 'student-course'pair and this student's mark of a course.
* @return the array of Record object containing 'student-course' information related to this student
*/
public ArrayList<Record> getRecordList() {
return recordList;
}
}