Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6fee2e981a | ||
|
|
5130cf9069 | ||
|
|
8ba322588e | ||
|
|
9731d3d3d7 |
+13
-11
@@ -71,9 +71,9 @@ public class Main {
|
|||||||
switch (choice) {
|
switch (choice) {
|
||||||
case 1:
|
case 1:
|
||||||
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;
|
||||||
@@ -108,10 +108,10 @@ public class Main {
|
|||||||
|
|
||||||
switch (choice) {
|
switch (choice) {
|
||||||
case 1:
|
case 1:
|
||||||
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 +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() + "!");
|
||||||
@@ -164,16 +164,18 @@ public class Main {
|
|||||||
|
|
||||||
private static void enrollInCourse(Student student) {
|
private static void enrollInCourse(Student student) {
|
||||||
System.out.print(school.getAllCoursesDisplay());
|
System.out.print(school.getAllCoursesDisplay());
|
||||||
System.out.print("\n Enter Course ID to enroll: ");
|
System.out.print("\nEnter 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)){
|
|
||||||
System.out.println("Successfully enrolled in" + course.getName());
|
if (student.enrollInCourse(course)) {
|
||||||
}else{
|
System.out.println(" Successfully enrolled in " + course.getName());
|
||||||
|
} else {
|
||||||
System.out.println(" You are already enrolled in this course!");
|
System.out.println(" You are already enrolled in this course!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ public class Student extends User {
|
|||||||
this.enrolledCourses = new ArrayList<>();
|
this.enrolledCourses = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean enrolledCourses(Course course){
|
public boolean enrollInCourse(Course course) {
|
||||||
if(enrolledCourses.contains(course)){
|
if (enrolledCourses.contains(course)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
enrolledCourses.add(course);
|
enrolledCourses.add(course);
|
||||||
@@ -20,17 +20,17 @@ public class Student extends User {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List <Course> getEnrolledCourses(){
|
public List<Course> getEnrolledCourses() {
|
||||||
return enrolledCourses;
|
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 Course: \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(". ").append(enrolledCourses.get(i)).append("\n");
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,16 +16,16 @@ public class SchoolSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ========== Student Management ==========
|
// ========== Student Management ==========
|
||||||
public boolean registerStudent(String username , String password){
|
public boolean registerStudent(String username, String password) {
|
||||||
if(findStudent(username) != null){
|
if (findStudent(username) != null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
students.add(new Student(username , password));
|
students.add(new Student(username, password));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Student loginStudent(String username, String password) {
|
public Student loginStudent(String username, String password) {
|
||||||
Student student = findStudent(username);
|
Student student = findStudent(username);
|
||||||
if (student != null && student.checkPassword(password)) {
|
if (student != null && student.checkPassword(password)) {
|
||||||
return student;
|
return student;
|
||||||
}
|
}
|
||||||
@@ -65,8 +65,8 @@ public class SchoolSystem {
|
|||||||
|
|
||||||
// ========== Course Management ==========
|
// ========== Course Management ==========
|
||||||
public boolean addCourseToSystem(String courseName) {
|
public boolean addCourseToSystem(String courseName) {
|
||||||
for (Course c : allCourses){
|
for (Course c : allCourses) {
|
||||||
if(c.getName().equals(courseName)){
|
if (c.getName().equals(courseName)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -75,10 +75,8 @@ 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){
|
if (c.getId() == id) return c;
|
||||||
return c;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user