-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudent.java
More file actions
47 lines (39 loc) · 902 Bytes
/
Student.java
File metadata and controls
47 lines (39 loc) · 902 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
45
46
47
import java.util.LinkedList;
import java.util.List;
/*
* @author Andrew Keyes
* Keyesandrew@live.com
*/
public class Student {
float averageGrade;
private LinkedList<Course> CourseesTaken;
public Student(){
CourseesTaken = new LinkedList<Course>();
}
public void addCourse(Course newCourse){
if(CourseesTaken.contains(newCourse)){
System.out.println("This course has already been added");
return;
}
else{
CourseesTaken.add(newCourse);
}
}
public LinkedList<Course> getCourses(){
return CourseesTaken;
}
public boolean removeCourse(Course removeCourse){
return CourseesTaken.remove(removeCourse);
}
public float getAverageGrade(){
int i=0;
float curGrade=0;
float sum=0;
while(CourseesTaken.get(i)!=null){
curGrade = CourseesTaken.get(i).getGrade()*CourseesTaken.get(i).getCredits();
sum=curGrade+sum;
i++;
}
return sum/i;
}
}