code and setup
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package models;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Teacher extends User {
|
||||
private List<Course> 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<Course> getMyCourses() {
|
||||
return myCourses;
|
||||
}
|
||||
|
||||
public void showMyCourses() {
|
||||
if (myCourses.isEmpty()) {
|
||||
System.out.println(" You don't teach any course yet.");
|
||||
} else {
|
||||
System.out.println("\n My Courses:");
|
||||
for (int i = 0; i < myCourses.size(); i++) {
|
||||
System.out.println(" " + (i+1) + ". " + myCourses.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void showStudentsInCourse(Course course) {
|
||||
if (!myCourses.contains(course)) {
|
||||
System.out.println(" You don't teach this course!");
|
||||
return;
|
||||
}
|
||||
course.showStudents();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user