-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudent.java
More file actions
59 lines (48 loc) · 1.17 KB
/
Student.java
File metadata and controls
59 lines (48 loc) · 1.17 KB
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
import java.util.ArrayList;
public class Student extends Person implements Payable{
private final ArrayList<Course> courses;
private double tuition;
public Student(String name, String id,double tuition){
super(name,id);
courses=new ArrayList<>();
this.tuition=tuition;
}
public void registerCourse(Course c){
// adds a course to arraylist
courses.add(c);
calculateTuition();
}
public void removeStudentCourse(String title){
for (Course c : courses) {
if (c.getCourseTitle().equalsIgnoreCase(title)) {
courses.remove(c);
return;
}
}
System.out.println("Course not found");
}
public void listCourses(){
if(courses.isEmpty()){
System.out.println("This student has no courses");
}
int count =1;
System.out.printf("\n");
for(Course c: courses){
System.out.printf("Course #: %d | Title: %s | Credits: %d \n",count,c.getCourseTitle(),c.getCourseCredits());
count++;
}
System.out.printf("\n");
}
@Override
public String getRole(){
return "Student";
}
public double getTuition(){
return this.tuition;
}
@Override
public double calculateTuition(){
this.tuition=courses.size()*236.34;
return courses.size()*236.34;
}
}