diff --git a/.idea/misc.xml b/.idea/misc.xml index e0844bc7be0a8ca77dcee74dfc4059ee4a9d4a1d..6ff90d33b95153014dc949e1cda4a8f72b8339d8 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 03e1ec7053246d3bc6e5ae10a7e4650328291a2f..4af953b81eb3d7291f1a97ec3acb91151cddd92f 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 2a4c8eff5462d97b8c43247c4de66fc6f05e5f06..119fad31a0c4f7d14de26eee9f8415fef36688f0 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 39d5d2b32b09c32149b8a80c73ef10311d4c7771..176cc8f681d0f90fa1ee3bcd8b0a876410281bdc 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 3e59c38fbd57497a72e78859efacc67ac75869da..4e1145b6406d321ceac06098439fa8e8a3ef8954 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 e3bd566bfe7445f8e0765d2d21ce23be8854879a..ae75dc92ab742c8d49effb72fda4d2e3cf7d5006 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 a3b5a1d24d299d9087a7a287097fc69106b755f6..05d3e012bb23544e6cf0a859355b80d6b56860c0 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 55e5b343b8d1bc879f7db2d58f3b2811ebabb16a..871129afb7a1d124da768b4c4c5e12587de4cfbd 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 1dd48c0cf9d44d13db1e1084928b3e9b81b20e59..92c4042a0fe57dcc66d367025af10f78fec469fe 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 7864a94a24eae57f7d0d20ef54f739adfbb16400..b958727c9058ac48d5a88a6b728ac1f90191466c 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; + } }