Skip to content
Snippets Groups Projects
Commit 9edf403b authored by Kevin Thaller's avatar Kevin Thaller
Browse files

first take on logic

parent ff7e793a
No related branches found
No related tags found
1 merge request!3jpa+gui+logic
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <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" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>
\ No newline at end of file
public interface Calcuable public interface Calcuable
{ {
double calculateAverage(); double calculateAverage();
int calculateMedian(); int calculateMedian(); //Wird vielleicht spaeter benoetigt
double calculateModus();
} }
...@@ -25,8 +25,19 @@ public class Course ...@@ -25,8 +25,19 @@ public class Course
this.examType = examType; 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;
} }
} }
import enumeration.Gender; import enumeration.Gender;
import enumeration.Mark;
import enumeration.Status; import enumeration.Status;
import java.util.List; 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, public Lecturer(int id, String firstName, String lastName, String placeOfResidence, String birthPlace,
String officialEmail, String privateEmail, List<Course> personalCourses, String officialEmail, String privateEmail, List<Course> personalCourses, Gender gender, Status status) {
boolean isSignedUpForCourse, Gender gender, Status status)
{
super(id, gender, firstName, lastName, placeOfResidence, birthPlace, super(id, gender, firstName, lastName, placeOfResidence, birthPlace,
officialEmail, privateEmail, personalCourses, isSignedUpForCourse); officialEmail, privateEmail, personalCourses);
} }
@Override public boolean rateStudent(Student student, Course course, Mark mark) {
public boolean signUpForCourse(Course course) if (isSignedUpForCourse(course)) {
{ return student.setGrade(course, mark);
}
return false; return false;
} }
} }
import enumeration.*;
import java.util.ArrayList;
import java.util.List;
public class Main { public class Main {
public static void main(String[] args) { 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
import enumeration.BachelorSemester; import enumeration.BachelorSemester;
import enumeration.Gender; import enumeration.Gender;
import enumeration.Mark;
import enumeration.Status; 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 // no static because variables don't make any sense without the created object
private Status status; private Status status;
private boolean paidFees; private boolean paidFees;
private BachelorSemester bachelorSemester; 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, public Student(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,
Status status, boolean paidFess, BachelorSemester bachelorSemester, List<Double> grades) Status status, BachelorSemester bachelorSemester) {
{
super(id, gender, firstName, lastName, placeOfResidence, birthPlace, super(id, gender, firstName, lastName, placeOfResidence, birthPlace,
officialEmail, privateEmail, personalCourses, isSignedUpForCourse); officialEmail, privateEmail, personalCourses);
this.status = status; this.status = status;
this.paidFees = paidFess; this.paidFees = true;
this.bachelorSemester = bachelorSemester; 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; return grades;
} }
public boolean increaseSemester() {
if (paidFees) {
bachelorSemester.increaseSemester();
return true;
} else {
return false;
}
}
@Override @Override
public boolean signUpForCourse(Course course) public double calculateAverage() {
{ double average = 0.0;
/* int counter = 0;
personalCourses.add(course); for (Map.Entry<Course, Mark> grade : grades.entrySet()) {
if (grade.getValue() != null) {
// return status for registration process: was successful or has failed Mark temp = grade.getValue();
return isSignedUpForCourse = true; average += temp.getValue();
*/ counter++;
return false; }
}
return average / counter;
} }
@Override @Override
public double calculateAverage() public int calculateMedian() {
{ List<Mark> markList = new ArrayList<>();
return 0; 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 @Override
public int calculateMedian() public double calculateModus() {
{ return 0.0;
return 0;
} }
} }
\ No newline at end of file
...@@ -3,8 +3,7 @@ import enumeration.Gender; ...@@ -3,8 +3,7 @@ import enumeration.Gender;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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 // final for the ID because it will remain the same for the whole duration of studying or being employed
// PK & FK // PK & FK
private final int id; private final int id;
...@@ -16,11 +15,10 @@ public abstract class UniversityMember ...@@ -16,11 +15,10 @@ public abstract class UniversityMember
private String officialEmail; private String officialEmail;
private String privateEmail; private String privateEmail;
private List<Course> personalCourses = new ArrayList<>(); private List<Course> personalCourses = new ArrayList<>();
private boolean isSignedUpForCourse;
public UniversityMember(int id, Gender gender, String firstName, String lastName, String placeOfResidence, String birthPlace, 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.id = id;
this.gender = gender; this.gender = gender;
this.firstName = firstName; this.firstName = firstName;
...@@ -30,8 +28,41 @@ public abstract class UniversityMember ...@@ -30,8 +28,41 @@ public abstract class UniversityMember
this.officialEmail = officialEmail; this.officialEmail = officialEmail;
this.privateEmail = privateEmail; this.privateEmail = privateEmail;
this.personalCourses = personalCourses; 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);
}
} }
...@@ -3,7 +3,8 @@ package enumeration; ...@@ -3,7 +3,8 @@ package enumeration;
public enum BachelorDegree public enum BachelorDegree
{ {
BACHELOR_OF_SCIENCE("B. Sc."), BACHELOR_OF_SCIENCE("B. Sc."),
BACHELOR_OF_ENGINEERING("B. Eng."); BACHELOR_OF_ENGINEERING("B. Eng."),
BACHELOR_OF_ARTS("B. A.");
private String degree; private String degree;
......
...@@ -12,8 +12,14 @@ public enum BachelorSemester ...@@ -12,8 +12,14 @@ public enum BachelorSemester
private int semester; private int semester;
//Max-Grenze festlegen
private BachelorSemester(int semester) private BachelorSemester(int semester)
{ {
this.semester = semester; this.semester = semester;
} }
public void increaseSemester(){
this.semester++;
}
} }
package enumeration; package enumeration;
public enum Mark public enum Mark {
{
EINS_NULL(1.0), EINS_NULL(1.0),
EINS_DREI(1.3), EINS_DREI(1.3),
EINS_SIEBEN(1.7), EINS_SIEBEN(1.7),
...@@ -14,10 +13,14 @@ public enum Mark ...@@ -14,10 +13,14 @@ public enum Mark
VIER_NULL(4.0), VIER_NULL(4.0),
FUENF_NULL(5.0); FUENF_NULL(5.0);
private double mark; private double mark;
Mark(double mark) private Mark(double mark) {
{
this.mark = mark; this.mark = mark;
} }
public double getValue() {
return mark;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment