1 Commits
Author SHA1 Message Date
ZahraSadatMirvakili 0c9fb2ff46 the workshop thecher and studend courses 2026-05-03 23:41:07 +03:30
3 changed files with 29 additions and 29 deletions
+2 -4
View File
@@ -151,7 +151,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() + "!");
@@ -166,14 +166,12 @@ public class Main {
System.out.print(school.getAllCoursesDisplay()); System.out.print(school.getAllCoursesDisplay());
System.out.print("\n Enter Course ID to enroll: "); System.out.print("\n Enter Course ID to enroll: ");
int courseId = getIntInput(); int courseId = getIntInput();
Course course = school.findCourseById(courseId); Course course = school.findCourseById(courseId);
if(course == null){ if(course == null){
System.out.println(" Course not found! Please enter a valid ID."); System.out.println(" Course not found! Please enter a valid ID.");
return; return;
} }
if(student.enrolledCourses(course)){
if (student.enrollInCourse(course)) {
System.out.println("Successfully enrolled in" + course.getName()); System.out.println("Successfully enrolled in" + course.getName());
}else{ }else{
System.out.println(" You are already enrolled in this course!"); System.out.println(" You are already enrolled in this course!");
+2 -2
View File
@@ -11,7 +11,7 @@ public class Student extends User {
this.enrolledCourses = new ArrayList<>(); this.enrolledCourses = new ArrayList<>();
} }
public boolean enrollInCourse(Course course) { public boolean enrolledCourses(Course course){
if(enrolledCourses.contains(course)){ if(enrolledCourses.contains(course)){
return false; return false;
} }
@@ -28,7 +28,7 @@ public class Student extends User {
if(enrolledCourses.isEmpty()){ if(enrolledCourses.isEmpty()){
return " You are not enrolled in any course yet."; return " You are not enrolled in any course yet.";
}else{ }else{
StringBuilder sb = new StringBuilder("\n My Courses:\n"); StringBuilder sb = new StringBuilder("\n My Course: \n");
for (int i = 0; i < enrolledCourses.size(); i++) { for (int i = 0; i < enrolledCourses.size(); i++) {
sb.append(" ").append(i+1).append(". ").append(enrolledCourses.get(i)).append("\n"); sb.append(" ").append(i+1).append(". ").append(enrolledCourses.get(i)).append("\n");
} }
+3 -1
View File
@@ -76,7 +76,9 @@ public class SchoolSystem {
public Course findCourseById(int id) { public Course findCourseById(int id) {
for(Course c : allCourses){ for(Course c : allCourses){
if (c.getId() == id) return c; if (c.getId() == id){
return c;
}
} }
return null; return null;
} }