38 lines
1.1 KiB
Java
38 lines
1.1 KiB
Java
package models;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class Student extends User {
|
|
private List<Course> enrolledCourses;
|
|
|
|
public Student(String username, String password) {
|
|
super(username, password);
|
|
this.enrolledCourses = new ArrayList<>();
|
|
}
|
|
|
|
public boolean enrollInCourse(Course course) {
|
|
if (enrolledCourses.contains(course)) {
|
|
return false;
|
|
}
|
|
enrolledCourses.add(course);
|
|
course.addStudent(this);
|
|
return true;
|
|
}
|
|
|
|
public List<Course> getEnrolledCourses() {
|
|
return enrolledCourses;
|
|
}
|
|
|
|
public String getMyCoursesDisplay() {
|
|
if (enrolledCourses.isEmpty()) {
|
|
return " You are not enrolled in any course yet.";
|
|
} else {
|
|
StringBuilder sb = new StringBuilder("\n My Courses:\n");
|
|
for (int i = 0; i < enrolledCourses.size(); i++) {
|
|
sb.append(" ").append(i+1).append(". ").append(enrolledCourses.get(i)).append("\n");
|
|
}
|
|
return sb.toString();
|
|
}
|
|
}
|
|
} |