Skip to content
Snippets Groups Projects
Student.java 2.66 KiB
Newer Older
import enumeration.BachelorSemester;
import enumeration.Gender;
Kevin Thaller's avatar
Kevin Thaller committed
import enumeration.Mark;
import enumeration.Status;

Kevin Thaller's avatar
Kevin Thaller committed
import java.util.*;
TayBone2305's avatar
TayBone2305 committed

Kevin Thaller's avatar
Kevin Thaller committed
public class Student extends UniversityMember implements Calcuable {
TayBone2305's avatar
TayBone2305 committed
    // no static because variables don't make any sense without the created object
    private Status status;
TayBone2305's avatar
TayBone2305 committed
    private boolean paidFees;
    private BachelorSemester bachelorSemester;
Kevin Thaller's avatar
Kevin Thaller committed
    private Map<Course, Mark> grades = new HashMap<>();

    public Student(int id, Gender gender, String firstName, String lastName, String placeOfResidence, String birthPlace,
Kevin Thaller's avatar
Kevin Thaller committed
                   String officialEmail, String privateEmail, List<Course> personalCourses,
                   Status status, BachelorSemester bachelorSemester) {
        super(id, gender, firstName, lastName, placeOfResidence, birthPlace,
Kevin Thaller's avatar
Kevin Thaller committed
                officialEmail, privateEmail, personalCourses);
        this.status = status;
Kevin Thaller's avatar
Kevin Thaller committed
        this.paidFees = true;
TayBone2305's avatar
TayBone2305 committed
        this.bachelorSemester = bachelorSemester;
Kevin Thaller's avatar
Kevin Thaller committed
        this.initGrades();
    }

    private void initGrades() {
        for (Course course : this.getPersonalCourses()) {
            grades.put(course, null);
        }
TayBone2305's avatar
TayBone2305 committed
    }
Kevin Thaller's avatar
Kevin Thaller committed
    public boolean setGrade(Course course, Mark mark) {
        if (isSignedUpForCourse(course)) {
            grades.replace(course, mark);
            return true;
        }
        return false;
    }


    public Map<Course, Mark> getGrades() {
TayBone2305's avatar
TayBone2305 committed
        return grades;
TayBone2305's avatar
TayBone2305 committed
    }
Kevin Thaller's avatar
Kevin Thaller committed

    public boolean increaseSemester() {
        if (paidFees) {
            bachelorSemester.increaseSemester();
            return true;
        } else {
            return false;
        }
    }


Kevin Thaller's avatar
Kevin Thaller committed
    public double calculateAverage() {
        double average = 0.0;
        int counter = 0;
        for (Map.Entry<Course, Mark> grade : grades.entrySet()) {
            if (grade.getValue() != null) {
                Mark temp = grade.getValue();
                average += temp.getValue();
                counter++;
            }
        }
        return average / counter;
Kevin Thaller's avatar
Kevin Thaller committed
    public int calculateMedian() {
        List<Mark> markList = new ArrayList<>();
        int median = 0;
        for (Map.Entry<Course, Mark> grade : grades.entrySet()) {
            if (grade.getValue() != null) {
                markList.add(grade.getValue());
            }
        }
        markList.sort(Comparator.comparing(Mark::getValue));
        median = (int) markList.get(markList.size() / 2).getValue();
        if (markList.size() % 2 == 0)
            median = (int) ((median + markList.get(markList.size() / 2 - 1).getValue()) / 2);
        return median;
Kevin Thaller's avatar
Kevin Thaller committed
    public double calculateModus() {
        return 0.0;
TayBone2305's avatar
TayBone2305 committed
}