77 lines
2.0 KiB
Java
77 lines
2.0 KiB
Java
package services;
|
|
|
|
import models.*;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class SchoolSystem {
|
|
private List<Student> students;
|
|
private List<Teacher> teachers;
|
|
private List<Course> allCourses;
|
|
|
|
public SchoolSystem() {
|
|
this.students = new ArrayList<>();
|
|
this.teachers = new ArrayList<>();
|
|
this.allCourses = new ArrayList<>();
|
|
}
|
|
|
|
// ========== Student Management ==========
|
|
//TODO
|
|
|
|
// ========== Teacher Management ==========
|
|
public boolean registerTeacher(String username, String password) {
|
|
if (findTeacher(username) != null) {
|
|
return false;
|
|
}
|
|
teachers.add(new Teacher(username, password));
|
|
return true;
|
|
}
|
|
|
|
public Teacher loginTeacher(String username, String password) {
|
|
Teacher teacher = findTeacher(username);
|
|
if (teacher != null && teacher.checkPassword(password)) {
|
|
return teacher;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private Teacher findTeacher(String username) {
|
|
for (Teacher t : teachers) {
|
|
if (t.getUsername().equals(username)) return t;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
// ========== Course Management ==========
|
|
public boolean addCourseToSystem(String courseName) {
|
|
//TODO
|
|
return true;
|
|
}
|
|
|
|
public Course findCourseById(int id) {
|
|
//TODO
|
|
return null;
|
|
}
|
|
|
|
public Course findCourseByName(String name) {
|
|
for (Course c : allCourses) {
|
|
if (c.getName().equalsIgnoreCase(name)) return c;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public void showAllCourses() {
|
|
if (allCourses.isEmpty()) {
|
|
System.out.println(" No courses available yet.");
|
|
} else {
|
|
System.out.println("\n All Available Courses:");
|
|
for (int i = 0; i < allCourses.size(); i++) {
|
|
System.out.println(" " + (i+1) + ". " + allCourses.get(i));
|
|
}
|
|
}
|
|
}
|
|
|
|
public List<Course> getAllCourses() {
|
|
return allCourses;
|
|
}
|
|
} |