Browse Source

Added the missing implementation for the Menu elements aside from Case 5

remotes/origin/fdai7780
fdai7600 11 months ago
parent
commit
e0c6b49c80
  1. 37
      src/main/java/org/example/Administration.java
  2. 38
      src/main/java/org/example/Main.java
  3. 10
      src/main/java/org/example/Student.java

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

@ -1,9 +1,6 @@
package org.example; package org.example;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
import java.util.*;
public class Administration { public class Administration {
/** /**
@ -509,6 +506,38 @@ public class Administration {
} }
public boolean assignGradeToStudent(String studentId, String courseId, String grade) {
Student student = findStudentById(studentId);
// First, find the course by ID to ensure it exists in the system.
Course course = findCourseByID(courseId);
if (student != null && course != null) {
// Check if the student is enrolled in the specified course.
if (student.getCourseGrades().containsKey(course)) {
// Student is enrolled in the course, proceed to assign the grade.
student.getCourseGrades().put(course, grade);
return true;
} else {
// Student is not enrolled in the specified course.
System.out.println("Student is not enrolled in the specified course.");
return false;
}
}
return false;
}
public void viewCourses() {
if (courses.isEmpty()) {
System.out.println("No courses available.");
} else {
System.out.println("Available Courses:");
for (Course course : courses) {
course.printCourseInfo();
}
}
}
} }

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

@ -30,10 +30,7 @@ public class Main {
System.out.println("8. View Courses"); System.out.println("8. View Courses");
System.out.println("9. Assign Grade to Student"); System.out.println("9. Assign Grade to Student");
System.out.println("10. View Grades from Student"); System.out.println("10. View Grades from Student");
System.out.println("11. View User");
System.out.println("12. Delete User");
System.out.println("13. View Course List");
System.out.println("14. Exit (includes saving data in the files)");
System.out.println("11. Exit (includes saving data in the files)");
System.out.print("Select an option: "); System.out.print("Select an option: ");
int choice = scanner.nextInt(); int choice = scanner.nextInt();
@ -84,23 +81,38 @@ public class Main {
break; break;
case 8: case 8:
// View Courses // View Courses
administration.viewCourses();
break; break;
case 9: case 9:
// Assign Grade to Student // Assign Grade to Student
System.out.println("Assign Grade to Student selected");
System.out.print("Enter Student ID: ");
String toBeGradedstudentId = scanner.next();
System.out.print("Enter Course ID: ");
String toBeGradedcourseId = scanner.next();
System.out.print("Enter Grade: ");
String grade = scanner.next();
boolean success = administration.assignGradeToStudent(toBeGradedstudentId, toBeGradedcourseId, grade);
if (success) {
System.out.println("Grade assigned successfully.");
} else {
System.out.println("Failed to assign grade. Ensure the student and course IDs are correct.");
}
break; break;
case 10: case 10:
// View Grades from Student // View Grades from Student
System.out.print("Enter Student ID to view grades: ");
String GradedstudentId = scanner.next();
Student student = administration.findStudentById(GradedstudentId);
if (student != null) {
student.printGrades();
} else {
System.out.println("Student not found.");
}
break; break;
case 11: case 11:
// View User
break;
case 12:
// Delete User
break;
case 13:
// View Course List
break;
case 14:
// Exit (includes saving data in the files) // Exit (includes saving data in the files)
exit = true; exit = true;
System.out.println("Exiting..."); System.out.println("Exiting...");

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

@ -107,6 +107,16 @@ public class Student {
return students; return students;
} }
public void assignGrade(Course course, String grade) {
// Assuming courseGrades is a Map<Course, String> where the course is the key and the grade is the value
this.courseGrades.put(course, grade);
}
public void printGrades() {
System.out.println("Grades for Student ID: " + this.studentId);
for (Map.Entry<Course, String> entry : courseGrades.entrySet()) {
System.out.println("Course: " + entry.getKey().getCourseName() + ", Grade: " + entry.getValue());
}
}
} }
Loading…
Cancel
Save