Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce71edefa5 |
+4
-28
@@ -70,12 +70,7 @@ public class Main {
|
|||||||
boolean success;
|
boolean success;
|
||||||
switch (choice) {
|
switch (choice) {
|
||||||
case 1:
|
case 1:
|
||||||
success = school.registerStudent(username, password);
|
//TODO
|
||||||
if (success) {
|
|
||||||
System.out.println(" Student registered successfully!");
|
|
||||||
} else {
|
|
||||||
System.out.println(" Username already exists!");
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
success = school.registerTeacher(username, password);
|
success = school.registerTeacher(username, password);
|
||||||
@@ -108,12 +103,7 @@ public class Main {
|
|||||||
|
|
||||||
switch (choice) {
|
switch (choice) {
|
||||||
case 1:
|
case 1:
|
||||||
Student student = school.loginStudent(username, password);
|
//TODO
|
||||||
if (student != null) {
|
|
||||||
studentMenu(student);
|
|
||||||
} else {
|
|
||||||
System.out.println(" Invalid username or password!");
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
Teacher teacher = school.loginTeacher(username, password);
|
Teacher teacher = school.loginTeacher(username, password);
|
||||||
@@ -151,7 +141,7 @@ public class Main {
|
|||||||
enrollInCourse(student);
|
enrollInCourse(student);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
System.out.print(student.getMyCoursesDisplay());
|
//System.out.print(student.getMyCoursesDisplay());
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
System.out.println(" Goodbye, " + student.getUsername() + "!");
|
System.out.println(" Goodbye, " + student.getUsername() + "!");
|
||||||
@@ -163,21 +153,7 @@ public class Main {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void enrollInCourse(Student student) {
|
private static void enrollInCourse(Student student) {
|
||||||
System.out.print(school.getAllCoursesDisplay());
|
//TODO
|
||||||
System.out.print("\nEnter Course ID to enroll: ");
|
|
||||||
int courseId = getIntInput();
|
|
||||||
|
|
||||||
Course course = school.findCourseById(courseId);
|
|
||||||
if (course == null) {
|
|
||||||
System.out.println(" Course not found! Please enter a valid ID.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (student.enrollInCourse(course)) {
|
|
||||||
System.out.println(" Successfully enrolled in " + course.getName());
|
|
||||||
} else {
|
|
||||||
System.out.println(" You are already enrolled in this course!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==================== TEACHER MENU ====================
|
// ==================== TEACHER MENU ====================
|
||||||
|
|||||||
@@ -11,28 +11,5 @@ public class Student extends User {
|
|||||||
this.enrolledCourses = new ArrayList<>();
|
this.enrolledCourses = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean enrollInCourse(Course course) {
|
//TODO
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -16,28 +16,7 @@ public class SchoolSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ========== Student Management ==========
|
// ========== Student Management ==========
|
||||||
public boolean registerStudent(String username, String password) {
|
//TODO
|
||||||
if (findStudent(username) != null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
students.add(new Student(username, password));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Student loginStudent(String username, String password) {
|
|
||||||
Student student = findStudent(username);
|
|
||||||
if (student != null && student.checkPassword(password)) {
|
|
||||||
return student;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Student findStudent(String username) {
|
|
||||||
for (Student s : students) {
|
|
||||||
if (s.getUsername().equals(username)) return s;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ========== Teacher Management ==========
|
// ========== Teacher Management ==========
|
||||||
public boolean registerTeacher(String username, String password) {
|
public boolean registerTeacher(String username, String password) {
|
||||||
@@ -65,19 +44,12 @@ public class SchoolSystem {
|
|||||||
|
|
||||||
// ========== Course Management ==========
|
// ========== Course Management ==========
|
||||||
public boolean addCourseToSystem(String courseName) {
|
public boolean addCourseToSystem(String courseName) {
|
||||||
for (Course c : allCourses) {
|
//TODO
|
||||||
if (c.getName().equals(courseName)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
allCourses.add(new Course(courseName));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Course findCourseById(int id) {
|
public Course findCourseById(int id) {
|
||||||
for (Course c : allCourses) {
|
//TODO
|
||||||
if (c.getId() == id) return c;
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user