-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudent.java
167 lines (143 loc) · 3.25 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
156
157
158
159
160
161
162
163
164
165
166
167
package uk.ac.rhul.cs2800.model;
import java.util.ArrayList;
/**
* Represents the Student class.
*/
public class Student {
private long id;
private String firstName;
private String lastName;
private String username;
private String email;
private ArrayList<Grade> gradelist;
private ArrayList<Registration> reglist; // registrations list
/**
* Constructs a Student with the given details.
*
* @param id students id
* @param firstName the student's first name
* @param lastName the student's last name
* @param username the student's username
* @param email the student's email address
*/
public Student(long id, String firstName, String lastName, String username, String email) {
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
this.username = username;
this.email = email;
this.gradelist = new ArrayList<Grade>();
this.reglist = new ArrayList<Registration>();
}
// Getters and setters
/**
* Returns the student's ID.
*
* @return id
*/
public long getId() {
return id;
}
/**
* Returns the student's first name.
*
* @return firstName
*/
public String getFirstName() {
return firstName;
}
/**
* Returns the student's last name.
*
* @return lastName
*/
public String getLastName() {
return lastName;
}
/**
* Returns the student's username.
*
* @return username
*/
public String getUsername() {
return username;
}
/**
* Returns the student's email.
*
* @return email
*/
public String getEmail() {
return email;
}
/**
* Adds grade to the arraylist.
*
*
*/
public void addGrade(Grade g) throws NoRegistrationException {
for (int i = 0; i < reglist.size(); i++) {
Module mo = reglist.get(i).getModule();
Module m = g.getModule();
if (mo == m) {
gradelist.add(g);
return;
}
}
throw new NoRegistrationException("This is a NoRegistratioNexception");
}
/**
* Registers new Module, meaning adding a registration referenced to the module to the
* Registration arraylist.
*
*
*/
public void registerModule(Module m) {
Registration r = new Registration(m);
reglist.add(r);
}
/**
* Computes average.
*
* @return averages
*/
public float computeAverage() throws NoGradeAvailableException {
int sum = 0;
for (int i = 0; i < gradelist.size(); i++) {
sum += gradelist.get(i).getScore();
}
if (sum == 0) {
throw new NoGradeAvailableException("This is a NoGradeAvailableException");
}
return (float) sum / (float) gradelist.size();
}
/**
* Computes average.
*
* @return averages
*/
public Grade getGrade(Module m) throws NoGradeAvailableException {
for (int i = 0; i < reglist.size(); i++) {
if (gradelist.get(i).getModule() == m) {
return gradelist.get(i);
}
}
throw new NoGradeAvailableException("This is a NoGradeAvailableException");
}
/**
* Computes average.
*
* @return averages
*/
public ArrayList<Grade> getGradelist() {
return this.gradelist;
}
/**
* Computes average.
*
* @return averages
*/
public ArrayList<Registration> getReglist() {
return this.reglist;
}
}