From 20d6af9614e0a59d08200f745c971defc5a1aa5f Mon Sep 17 00:00:00 2001 From: fdai7600 Date: Thu, 8 Feb 2024 21:44:27 +0100 Subject: [PATCH 1/2] Implemented cae 10 To view Grades from Student --- src/main/java/org/example/Administration.java | 9 +++++++++ src/main/java/org/example/Main.java | 3 +++ src/main/java/org/example/Student.java | 9 ++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/example/Administration.java b/src/main/java/org/example/Administration.java index 07f5a16..8695a8c 100644 --- a/src/main/java/org/example/Administration.java +++ b/src/main/java/org/example/Administration.java @@ -552,6 +552,15 @@ public class Administration { return false; } + public void viewGradesFromStudent(String studentId) { + Student student = findStudentById(studentId); + if (student != null) { + student.printGrades(); + } else { + System.out.println("Student with ID " + studentId + " not found."); + } + } + } diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/example/Main.java index c22840f..c1b1e87 100644 --- a/src/main/java/org/example/Main.java +++ b/src/main/java/org/example/Main.java @@ -96,6 +96,9 @@ public class Main { break; case 10: // View Grades from Student + System.out.print("Enter Student ID to view grades: "); + String studentId = scanner.next(); + administration.viewGradesFromStudent(studentId); break; case 11: diff --git a/src/main/java/org/example/Student.java b/src/main/java/org/example/Student.java index 8cfe740..a0b7074 100644 --- a/src/main/java/org/example/Student.java +++ b/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 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")); + } + } } From c80a4dd63634ef3681c3ce2f6ef195ea3fb824a5 Mon Sep 17 00:00:00 2001 From: fdai7600 Date: Thu, 8 Feb 2024 21:49:36 +0100 Subject: [PATCH 2/2] refactoring: encapsulated the input handling related with case 10 --- src/main/java/org/example/Administration.java | 5 ++++- src/main/java/org/example/Main.java | 4 +--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/example/Administration.java b/src/main/java/org/example/Administration.java index 8695a8c..e44611f 100644 --- a/src/main/java/org/example/Administration.java +++ b/src/main/java/org/example/Administration.java @@ -552,8 +552,11 @@ public class Administration { return false; } - public void viewGradesFromStudent(String studentId) { + 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 { diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/example/Main.java index c1b1e87..8c45a49 100644 --- a/src/main/java/org/example/Main.java +++ b/src/main/java/org/example/Main.java @@ -96,9 +96,7 @@ public class Main { break; case 10: // View Grades from Student - System.out.print("Enter Student ID to view grades: "); - String studentId = scanner.next(); - administration.viewGradesFromStudent(studentId); + administration.viewGradesFromStudent(); break; case 11: