-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudent.java
79 lines (52 loc) · 1.29 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
import java.util.ArrayList;
public class Student {
public static final int MIN_AGE = 14;
public static final int MAX_AGE = 90;
public static final int MIN_GRADE = 1;
public static final int MAX_GRADE = 10;
public static final int MIN_NAME_SIZE = 3;
public static final int MAX_NAME_SIZE = 255;
protected String name;
protected int age;
protected ArrayList<Integer> grades;
public Student(String name, int age, ArrayList<Integer> grades) {
super();
this.name = name;
this.age = age;
this.grades = grades;
}
public String getName() {
return name;
}
public void setName(String name) throws WrongNameException{
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) throws WrongAgeException {
if(age < MIN_AGE || age > MAX_AGE) {
throw new WrongAgeException();
}
this.age = age;
}
public void setGrades(ArrayList<Integer> grades) throws WrongGradesException{
this.grades = grades;
}
public int getGrade(int index) {
return this.grades.get(index);
}
public int getNoGrades() {
return this.grades.size();
}
public float getGradesAverage() {
if(this.grades.size() == 0) {
return 0;
}
float sum = 0;
for(int grade : this.grades) {
sum += grade;
}
return sum/this.grades.size();
}
}