package models; import java.util.ArrayList; import java.util.List; public class Teacher extends User { private List myCourses; public Teacher(String username, String password) { super(username, password); this.myCourses = new ArrayList<>(); } public boolean addCourse(Course course) { if (myCourses.contains(course)) { return false; } myCourses.add(course); course.setTeacher(this); return true; } public boolean removeCourse(Course course) { if (myCourses.remove(course)) { course.setTeacher(null); return true; } return false; } public List getMyCourses() { return myCourses; } public String getMyCoursesDisplay() { if (myCourses.isEmpty()) { return " You don't teach any course yet."; } else { StringBuilder sb = new StringBuilder("\n My Courses:\n"); for (int i = 0; i < myCourses.size(); i++) { sb.append(" ").append(i+1).append(". ").append(myCourses.get(i)).append("\n"); } return sb.toString(); } } public boolean checkCourseOwnership(Course course) { return myCourses.contains(course); } public String getStudentsDisplayForCourse(Course course) { if (!myCourses.contains(course)) { return "You don't teach this course!"; } return course.getStudentsDisplay(); } }