Browse Source

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/main/java/org/example/Administration.java
#	src/test/java/org/example/AdministrationTest.java
remotes/origin/fdai7887
fdai7887 11 months ago
parent
commit
4c43b68e18
  1. 23
      src/main/java/org/example/Administration.java
  2. 7
      src/main/java/org/example/Main.java
  3. 9
      src/main/java/org/example/Student.java
  4. 28
      src/test/java/org/example/AdministrationTest.java

23
src/main/java/org/example/Administration.java

@ -506,6 +506,17 @@ public class Administration {
}
}
public void enrollStudentInCourseInteractive() {
System.out.println("Enter Student ID:");
String studentId = scanner.nextLine(); // Use nextLine for consistent input handling
System.out.println("Enter Course ID:");
String courseId = scanner.nextLine();
boolean enrolled = enrollStudentInCourse(studentId, courseId);
// Feedback for failure is handled within the enrollStudentInCourse method
}
public void viewCourses() {
if (courses.isEmpty()) {
System.out.println("No courses available.");
@ -561,6 +572,18 @@ public class Administration {
}
public void viewGradesFromStudent() {
System.out.print("Enter Student ID to view grades: ");
String studentId = scanner.next();
Student student = findStudentById(studentId);
if (student != null) {
student.printGrades();
} else {
System.out.println("Student with ID " + studentId + " not found.");
}
}
}

7
src/main/java/org/example/Main.java

@ -41,11 +41,7 @@ public class Main {
administration.registerUser();
break;
case 2: // Enroll Student in Course
System.out.println("Enter Student ID:");
String studentId = scanner.next();
System.out.println("Enter Course ID:");
String courseId = scanner.next();
administration.enrollStudentInCourse(studentId, courseId);
administration.enrollStudentInCourseInteractive();
break;
case 3:
// Enroll Prof to Course
@ -108,6 +104,7 @@ public class Main {
break;
case 10:
// View Grades from Student
administration.viewGradesFromStudent();
break;
case 11:

9
src/main/java/org/example/Student.java

@ -111,6 +111,13 @@ public class Student {
this.courseGrades.put(course, grade);
}
public void printGrades() {
System.out.println("Grades for Student ID: " + this.studentId + ", Name: " + this.studentName);
for (Map.Entry<Course, String> entry : courseGrades.entrySet()) {
Course course = entry.getKey();
String grade = entry.getValue();
System.out.println("Course: " + course.getCourseName() + " (" + course.getCourseID() + "), Grade: " + (grade != null ? grade : "Not graded yet"));
}
}
}

28
src/test/java/org/example/AdministrationTest.java

@ -419,6 +419,34 @@ class AdministrationTest {
assertEquals("Student",administration.findStudentById("S1010").getStudentRole());
}
@Test
void testEnrollStudentInCourseInteractive() {
Administration administration = new Administration();
Student stud = sampleStudent;
administration.addStudents(stud);
Course course = sampleCourse;
administration.addCourse(course);
String studentId =stud.getStudentId(); // Use nextLine for consistent input handling
String courseId = course.getCourseID();
boolean enrolled = administration.enrollStudentInCourse(studentId, courseId);
boolean correct = false;
Map<Course, String> courses = stud.getCourseGrades();
for(Course key : courses.keySet())
{
if(key == course)
{
correct = true;
break;
}
}
assertTrue(correct);
}
@Test
void dropStudentFromCourse() {
Student student = sampleStudent;

Loading…
Cancel
Save