From 9edf403b2b6ad43a14fea6bc1794a6e9200cd56e Mon Sep 17 00:00:00 2001
From: Kevin Thaller <kevin.thaller@stud.th-deg.de>
Date: Mon, 23 May 2022 13:24:23 +0200
Subject: [PATCH] first take on logic

---
 .idea/misc.xml                        |  2 +-
 src/Calcuable.java                    |  3 +-
 src/Course.java                       | 15 ++++-
 src/Lecturer.java                     | 19 +++---
 src/Main.java                         | 43 ++++++++++++-
 src/Student.java                      | 91 +++++++++++++++++++--------
 src/UniversityMember.java             | 45 ++++++++++---
 src/enumeration/BachelorDegree.java   |  3 +-
 src/enumeration/BachelorSemester.java |  6 ++
 src/enumeration/Mark.java             | 11 ++--
 10 files changed, 185 insertions(+), 53 deletions(-)

diff --git a/.idea/misc.xml b/.idea/misc.xml
index e0844bc..6ff90d3 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_12" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
     <output url="file://$PROJECT_DIR$/out" />
   </component>
 </project>
\ No newline at end of file
diff --git a/src/Calcuable.java b/src/Calcuable.java
index 03e1ec7..4af953b 100644
--- a/src/Calcuable.java
+++ b/src/Calcuable.java
@@ -1,5 +1,6 @@
 public interface Calcuable
 {
     double calculateAverage();
-    int calculateMedian();
+    int calculateMedian(); //Wird vielleicht spaeter benoetigt
+    double calculateModus();
 }
diff --git a/src/Course.java b/src/Course.java
index 2a4c8ef..119fad3 100644
--- a/src/Course.java
+++ b/src/Course.java
@@ -25,8 +25,19 @@ public class Course
         this.examType = examType;
     }
 
-    public void setGrade(Mark mark)
-    {
+    public int getId(){
+        return id;
+    }
 
+    @Override
+    public String toString() {
+        return "\nCourse: " +
+                "id=" + id +
+                ", name='" + name + '\'' +
+                ", bachelorSemester=" + bachelorSemester +
+                ", courseType=" + courseType +
+                ", sws=" + sws +
+                ", ects=" + ects +
+                ", examType=" + examType;
     }
 }
diff --git a/src/Lecturer.java b/src/Lecturer.java
index 39d5d2b..176cc8f 100644
--- a/src/Lecturer.java
+++ b/src/Lecturer.java
@@ -1,21 +1,22 @@
 import enumeration.Gender;
+import enumeration.Mark;
 import enumeration.Status;
 
 import java.util.List;
 
-public class Lecturer extends UniversityMember
-{
+public class Lecturer extends UniversityMember {
     public Lecturer(int id, String firstName, String lastName, String placeOfResidence, String birthPlace,
-                    String officialEmail, String privateEmail, List<Course> personalCourses,
-                    boolean isSignedUpForCourse, Gender gender, Status status)
-    {
+                    String officialEmail, String privateEmail, List<Course> personalCourses, Gender gender, Status status) {
         super(id, gender, firstName, lastName, placeOfResidence, birthPlace,
-                officialEmail, privateEmail, personalCourses, isSignedUpForCourse);
+                officialEmail, privateEmail, personalCourses);
     }
 
-    @Override
-    public boolean signUpForCourse(Course course)
-    {
+    public boolean rateStudent(Student student, Course course, Mark mark) {
+        if (isSignedUpForCourse(course)) {
+            return student.setGrade(course, mark);
+        }
         return false;
     }
+
+
 }
diff --git a/src/Main.java b/src/Main.java
index 3e59c38..4e1145b 100644
--- a/src/Main.java
+++ b/src/Main.java
@@ -1,5 +1,46 @@
+import enumeration.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
 public class Main {
     public static void main(String[] args) {
-        System.out.println("Hello world!");
+
+
+        List<Course> kevCourses = new ArrayList<>();
+
+        Course a1 = new Course(1, "test1", BachelorSemester.FIFTH, CourseType.COMPULSORY, 5, 5.5, ExamType.ASSIGNMENT);
+        Course a2 = new Course(2, "test2", BachelorSemester.FIFTH, CourseType.COMPULSORY, 5, 5.5, ExamType.ASSIGNMENT);
+        Course a3 = new Course(3, "test3", BachelorSemester.FIFTH, CourseType.COMPULSORY, 5, 5.5, ExamType.ASSIGNMENT);
+        Course a4 = new Course(4, "test4", BachelorSemester.FIFTH, CourseType.COMPULSORY, 5, 5.5, ExamType.ASSIGNMENT);
+        Course a5 = new Course(4, "test4", BachelorSemester.FIFTH, CourseType.COMPULSORY, 5, 5.5, ExamType.ASSIGNMENT);
+        Course a6 = new Course(4, "test4", BachelorSemester.FIFTH, CourseType.COMPULSORY, 5, 5.5, ExamType.ASSIGNMENT);
+        Course a7 = new Course(4, "test4", BachelorSemester.FIFTH, CourseType.COMPULSORY, 5, 5.5, ExamType.ASSIGNMENT);
+
+        kevCourses.add(a1);
+        kevCourses.add(a2);
+        kevCourses.add(a3);
+        kevCourses.add(a4);
+        kevCourses.add(a5);
+        kevCourses.add(a6);
+        kevCourses.add(a7);
+
+        Student kev = new Student(1, Gender.MALE, "Kevin",
+                "Thaller", "Tittling", "Freyung", "kevin.thaller@stud.th-deg.de",
+                "123", kevCourses, Status.ENROLLED, BachelorSemester.FIFTH);
+
+
+        kev.setGrade(a1, Mark.VIER_NULL);
+        kev.setGrade(a2, Mark.FUENF_NULL);
+        kev.setGrade(a3, Mark.DREI_DREI);
+        kev.setGrade(a4, Mark.EINS_NULL);
+        kev.setGrade(a5, Mark.EINS_NULL);
+        kev.setGrade(a6, Mark.FUENF_NULL);
+        kev.setGrade(a7, Mark.FUENF_NULL);
+
+        System.out.println(kev.getGrades());
+        System.out.println(kev.calculateAverage());
+        System.out.println(kev.calculateMedian());
+
     }
 }
\ No newline at end of file
diff --git a/src/Student.java b/src/Student.java
index e3bd566..ae75dc9 100644
--- a/src/Student.java
+++ b/src/Student.java
@@ -1,55 +1,92 @@
 import enumeration.BachelorSemester;
 import enumeration.Gender;
+import enumeration.Mark;
 import enumeration.Status;
 
-import java.util.List;
+import java.util.*;
 
-public class Student extends UniversityMember implements Calcuable
-{
+public class Student extends UniversityMember implements Calcuable {
     // no static because variables don't make any sense without the created object
     private Status status;
     private boolean paidFees;
     private BachelorSemester bachelorSemester;
-    private List<Double> grades;
+    private Map<Course, Mark> grades = new HashMap<>();
+
 
     public Student(int id, Gender gender, String firstName, String lastName, String placeOfResidence, String birthPlace,
-                   String officialEmail, String privateEmail, List<Course> personalCourses, boolean isSignedUpForCourse,
-                   Status status, boolean paidFess, BachelorSemester bachelorSemester, List<Double> grades)
-    {
+                   String officialEmail, String privateEmail, List<Course> personalCourses,
+                   Status status, BachelorSemester bachelorSemester) {
         super(id, gender, firstName, lastName, placeOfResidence, birthPlace,
-                officialEmail, privateEmail, personalCourses, isSignedUpForCourse);
+                officialEmail, privateEmail, personalCourses);
         this.status = status;
-        this.paidFees = paidFess;
+        this.paidFees = true;
         this.bachelorSemester = bachelorSemester;
-        this.grades = grades;
+        this.initGrades();
+    }
+
+    private void initGrades() {
+        for (Course course : this.getPersonalCourses()) {
+            grades.put(course, null);
+        }
     }
 
-    public List<Double> getGrades()
-    {
+    public boolean setGrade(Course course, Mark mark) {
+        if (isSignedUpForCourse(course)) {
+            grades.replace(course, mark);
+            return true;
+        }
+        return false;
+    }
+
+
+    public Map<Course, Mark> getGrades() {
         return grades;
     }
 
+
+    public boolean increaseSemester() {
+        if (paidFees) {
+            bachelorSemester.increaseSemester();
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+
     @Override
-    public boolean signUpForCourse(Course course)
-    {
-        /*
-        personalCourses.add(course);
-
-        // return status for registration process: was successful or has failed
-        return isSignedUpForCourse = true;
-        */
-        return false;
+    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;
     }
 
     @Override
-    public double calculateAverage()
-    {
-        return 0;
+    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;
     }
 
     @Override
-    public int calculateMedian()
-    {
-        return 0;
+    public double calculateModus() {
+        return 0.0;
     }
+
 }
\ No newline at end of file
diff --git a/src/UniversityMember.java b/src/UniversityMember.java
index a3b5a1d..05d3e01 100644
--- a/src/UniversityMember.java
+++ b/src/UniversityMember.java
@@ -3,8 +3,7 @@ import enumeration.Gender;
 import java.util.ArrayList;
 import java.util.List;
 
-public abstract class UniversityMember
-{
+public abstract class UniversityMember {
     // final for the ID because it will remain the same for the whole duration of studying or being employed
     // PK & FK
     private final int id;
@@ -16,11 +15,10 @@ public abstract class UniversityMember
     private String officialEmail;
     private String privateEmail;
     private List<Course> personalCourses = new ArrayList<>();
-    private boolean isSignedUpForCourse;
+
 
     public UniversityMember(int id, Gender gender, String firstName, String lastName, String placeOfResidence, String birthPlace,
-                            String officialEmail, String privateEmail, List<Course> personalCourses, boolean isSignedUpForCourse)
-    {
+                            String officialEmail, String privateEmail, List<Course> personalCourses) {
         this.id = id;
         this.gender = gender;
         this.firstName = firstName;
@@ -30,8 +28,41 @@ public abstract class UniversityMember
         this.officialEmail = officialEmail;
         this.privateEmail = privateEmail;
         this.personalCourses = personalCourses;
-        this.isSignedUpForCourse = isSignedUpForCourse;
     }
 
-    public abstract boolean signUpForCourse(Course course);
+    public Course getCourseForId(int id) {
+        for (Course course : personalCourses) {
+            if (course.getId() == id) {
+                return course;
+            }
+        }
+        return null;
+    }
+
+    public List<Course> getPersonalCourses() {
+        return personalCourses;
+    }
+
+    public boolean signUpForCourse(Course course) {
+        if (isSignedUpForCourse(course)) {
+            return false;
+        } else {
+            return personalCourses.add(course);
+        }
+
+    }
+
+    public boolean leaveCourse(Course course) {
+        if (isSignedUpForCourse(course)) {
+            return personalCourses.remove(course);
+        } else {
+            return false;
+        }
+
+    }
+
+    public boolean isSignedUpForCourse(Course course) {
+        return personalCourses.contains(course);
+    }
+
 }
diff --git a/src/enumeration/BachelorDegree.java b/src/enumeration/BachelorDegree.java
index 55e5b34..871129a 100644
--- a/src/enumeration/BachelorDegree.java
+++ b/src/enumeration/BachelorDegree.java
@@ -3,7 +3,8 @@ package enumeration;
 public enum BachelorDegree
 {
     BACHELOR_OF_SCIENCE("B. Sc."),
-    BACHELOR_OF_ENGINEERING("B. Eng.");
+    BACHELOR_OF_ENGINEERING("B. Eng."),
+    BACHELOR_OF_ARTS("B. A.");
 
     private String degree;
 
diff --git a/src/enumeration/BachelorSemester.java b/src/enumeration/BachelorSemester.java
index 1dd48c0..92c4042 100644
--- a/src/enumeration/BachelorSemester.java
+++ b/src/enumeration/BachelorSemester.java
@@ -12,8 +12,14 @@ public enum BachelorSemester
 
     private int semester;
 
+    //Max-Grenze festlegen
+
     private BachelorSemester(int semester)
     {
         this.semester = semester;
     }
+
+    public void increaseSemester(){
+        this.semester++;
+    }
 }
diff --git a/src/enumeration/Mark.java b/src/enumeration/Mark.java
index 7864a94..b958727 100644
--- a/src/enumeration/Mark.java
+++ b/src/enumeration/Mark.java
@@ -1,7 +1,6 @@
 package enumeration;
 
-public enum Mark
-{
+public enum Mark {
     EINS_NULL(1.0),
     EINS_DREI(1.3),
     EINS_SIEBEN(1.7),
@@ -14,10 +13,14 @@ public enum Mark
     VIER_NULL(4.0),
     FUENF_NULL(5.0);
 
+
     private double mark;
 
-    Mark(double mark)
-    {
+    private Mark(double mark) {
         this.mark = mark;
     }
+
+    public double getValue() {
+        return mark;
+    }
 }
-- 
GitLab