forked from fmendozaro/junit-tests
-
Notifications
You must be signed in to change notification settings - Fork 622
Expand file tree
/
Copy pathStudent.java
More file actions
44 lines (36 loc) · 966 Bytes
/
Student.java
File metadata and controls
44 lines (36 loc) · 966 Bytes
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
import java.util.ArrayList;
public class Student {
private long id;
private String name;
private ArrayList<Integer> grades;
public Student(String name, long id){
this.name = name;
this.id = id;
this.grades = new ArrayList<Integer>();
}
// returns the student's id
public long getId(){
return this.id;
}
// returns the student's name
public String getName(){
return this.name;
}
// adds the given grade to the grades list
public void addGrade(int grade){
this.grades.add(grade);
}
// returns the list of grades
public ArrayList<Integer> getGrades(){
return this.grades;
}
// returns the average of the students grades
public double getGradeAverage(){
int length = this.grades.size();
long sum = 0;
for (long grade : this.grades){
sum += grade;
}
return (sum/length);
}
}