Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7e56379458 |
+11
-18
@@ -73,7 +73,8 @@ public class Main {
|
|||||||
success = school.registerStudent(username, password);
|
success = school.registerStudent(username, password);
|
||||||
if(success){
|
if(success){
|
||||||
System.out.println(" Student registered successfully!");
|
System.out.println(" Student registered successfully!");
|
||||||
} else {
|
}
|
||||||
|
else{
|
||||||
System.out.println(" Username already exists!");
|
System.out.println(" Username already exists!");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -111,7 +112,8 @@ public class Main {
|
|||||||
Student student = school.loginStudent(username, password);
|
Student student = school.loginStudent(username, password);
|
||||||
if(student != null){
|
if(student != null){
|
||||||
studentMenu(student);
|
studentMenu(student);
|
||||||
} else {
|
}
|
||||||
|
else{
|
||||||
System.out.println(" Invalid username or password!");
|
System.out.println(" Invalid username or password!");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -151,7 +153,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 +165,12 @@ public class Main {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void enrollInCourse(Student student) {
|
private static void enrollInCourse(Student student) {
|
||||||
System.out.print(school.getAllCoursesDisplay());
|
System.out.println("\n Select a course:\n");
|
||||||
System.out.print("\nEnter Course ID to enroll: ");
|
school.getAllCoursesDisplay();
|
||||||
int courseId = getIntInput();
|
System.out.println();
|
||||||
|
String courseName = scanner.toString();
|
||||||
Course course = school.findCourseById(courseId);
|
Course course = school.findCourseByName(courseName);
|
||||||
if (course == null) {
|
student.enrollInCourse(course);
|
||||||
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,6 +11,10 @@ public class Student extends User {
|
|||||||
this.enrolledCourses = new ArrayList<>();
|
this.enrolledCourses = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Course> getEnrolledCourses() {
|
||||||
|
return enrolledCourses;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean enrollInCourse(Course course){
|
public boolean enrollInCourse(Course course){
|
||||||
if(enrolledCourses.contains(course)){
|
if(enrolledCourses.contains(course)){
|
||||||
return false;
|
return false;
|
||||||
@@ -20,19 +24,17 @@ public class Student extends User {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Course> getEnrolledCourses() {
|
|
||||||
return enrolledCourses;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMyCoursesDisplay(){
|
public String getMyCoursesDisplay(){
|
||||||
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 Courses:\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(enrolledCourses.get(i)).append("\n");
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -32,9 +32,11 @@ public class SchoolSystem {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Student findStudent(String username) {
|
public Student findStudent(String username){
|
||||||
for(Student s : students){
|
for(Student s : students){
|
||||||
if (s.getUsername().equals(username)) return s;
|
if(s.getUsername().equals(username)){
|
||||||
|
return s;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -76,7 +78,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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user