Browse Source

Improved Documentation in Student class

remotes/origin/fdai7887
fdai7887 11 months ago
parent
commit
5e75c4c216
  1. 29
      src/main/java/org/example/Student.java

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

@ -33,6 +33,10 @@ public class Student {
this.studentRole = role;
}
/**
* Various setter and getter for Student class
*
*/
public String getStudentName() {
return studentName;
}
@ -77,7 +81,12 @@ public class Student {
System.out.println("Role: " + getStudentRole());
}
/**
* Writes Data of a Student to a File
* @param student The Student whose data is being written
* @param filename The Name of the File to which the data is written
* @throws IOException
*/
public void writeToFile(Student student, String filename) throws IOException {
try(BufferedWriter writer = new BufferedWriter(new FileWriter(filename))){
String attributes = student.getStudentName() + "\n" + student.getStudentId() + "\n" + student.getStudentRole();
@ -86,6 +95,11 @@ public class Student {
}
/**
* Generates a List of Students from a file
* @param filename Name of the file which is being read
* @return returns List of all Student Data written in that file
*/
public static List<Student> readFromFile(String filename)
{
List<Student> students = new ArrayList<>();
@ -107,10 +121,19 @@ public class Student {
return students;
}
/**
* Assigns a grade to a specific course and records it in the courseGrades map.
* @param course The course for which the grade is being assigned.
* @param grade The grade to be assigned (e.g., "A", "B", "C", etc.).
*
*/
public void assignGrade(Course course, String grade) {
this.courseGrades.put(course, grade);
}
/**
* This Method prints the Grade of a Student to the console
*/
public void printGrades() {
System.out.println("Grades for Student ID: " + this.studentId + ", Name: " + this.studentName);
for (Map.Entry<Course, String> entry : courseGrades.entrySet()) {
@ -120,6 +143,10 @@ public class Student {
}
}
/**
* This method calculates the total credit points of a Student
* @return the credit points are being returned as an int
*/
public int calculateTotalCredits() {
int totalCredits = 0;
for (Course course : courseGrades.keySet()) {

Loading…
Cancel
Save