diff --git a/bin/App.class b/bin/App.class index fd1cc97..08e9a41 100644 Binary files a/bin/App.class and b/bin/App.class differ diff --git a/bin/Break.class b/bin/Break.class index 26cebca..aadcbf8 100644 Binary files a/bin/Break.class and b/bin/Break.class differ diff --git a/bin/BreakSchedule.class b/bin/BreakSchedule.class index 1dc403c..6e99e65 100644 Binary files a/bin/BreakSchedule.class and b/bin/BreakSchedule.class differ diff --git a/bin/Co2Data.class b/bin/Co2Data.class index cec42f0..cac907c 100644 Binary files a/bin/Co2Data.class and b/bin/Co2Data.class differ diff --git a/bin/Date.class b/bin/Date.class index cff29c2..f4d3eb4 100644 Binary files a/bin/Date.class and b/bin/Date.class differ diff --git a/bin/Points.class b/bin/Points.class index 0e69398..e376714 100644 Binary files a/bin/Points.class and b/bin/Points.class differ diff --git a/bin/Teacher.class b/bin/Teacher.class index 69117f6..19c1c18 100644 Binary files a/bin/Teacher.class and b/bin/Teacher.class differ diff --git a/bin/TimeTable.class b/bin/TimeTable.class index c2b7ad2..bb7d644 100644 Binary files a/bin/TimeTable.class and b/bin/TimeTable.class differ diff --git a/src/App.class b/src/App.class new file mode 100644 index 0000000..3c694b3 Binary files /dev/null and b/src/App.class differ diff --git a/src/App.java b/src/App.java index 12232f9..b112716 100644 --- a/src/App.java +++ b/src/App.java @@ -48,6 +48,13 @@ public class App { teacher.addPoints(breakPoints, 0, 0); } + // if it is smaller than 2 points the teacher does not deserve bonus points + if (breakPoints > 2) { + calculateBonusPoints(calcBreak, teacher, nextTeacher); + } + } + + private static void calculateBonusPoints(Break calcBreak, Teacher teacher, Teacher nextTeacher) { if (teacher.getShortName() != nextTeacher.getShortName()) { teacher.addPoints(0, 0, 5); } @@ -112,6 +119,7 @@ public class App { while (true) { int userInput = getUserInput("Do you want to see how the points were calculated? (1 = Yes, 0 = No)"); if (userInput == 1) { + printTeachers(true); printExplanation(); break; } else if (userInput == 0) { @@ -150,7 +158,7 @@ public class App { (a, b) -> Integer.compare(b.getTotalPoints(), a.getTotalPoints())); } - private static void printTeachers() { + private static void printTeachers(boolean detailed) { int rank = 1; int previousPoints = -1; @@ -162,7 +170,11 @@ public class App { rank = i + 1; previousPoints = teacherPoints; } - System.out.println(rank + ". " + teacher.getName() + " - Points: " + teacherPoints); + if (detailed) { + System.out.println(rank + ". " + teacher.getName() + " - " + teacher.detailedPointString()); + } else { + System.out.println(rank + ". " + teacher.getName() + " - Points: " + teacherPoints); + } } } @@ -233,14 +245,14 @@ public class App { calculateBreakPoints(longBreaks[i], teacher, nextTeacher); } } - } catch (Exception e) { - System.out.println("Error processing data for date: " + date + ". " + e.getMessage()); + } catch (MalformedURLException e) { + System.out.println("Error processing data for date: " + date + ". " + e); } } } sortTeachers(); - printTeachers(); + printTeachers(false); interactWithUser(); } catch (Exception e) { diff --git a/src/Break.class b/src/Break.class new file mode 100644 index 0000000..4f922e8 Binary files /dev/null and b/src/Break.class differ diff --git a/src/Break.java b/src/Break.java index 2e182f0..937f5c1 100644 --- a/src/Break.java +++ b/src/Break.java @@ -1,8 +1,10 @@ public class Break { + // #region Fields private int start; private int end; - private Co2Data co2Datas[]; + private Co2Data[] co2Datas; + // #region Getters and Setters public int getStart() { return start; } @@ -27,10 +29,10 @@ public class Break { this.co2Datas = co2Datas; } + // #region Constructor public Break(int start, int end, Co2Data[] co2Datas) { this.start = start; this.end = end; this.co2Datas = co2Datas; } - } diff --git a/src/BreakSchedule.class b/src/BreakSchedule.class new file mode 100644 index 0000000..36000fa Binary files /dev/null and b/src/BreakSchedule.class differ diff --git a/src/BreakSchedule.java b/src/BreakSchedule.java index ca2b2c2..3fdc7fc 100644 --- a/src/BreakSchedule.java +++ b/src/BreakSchedule.java @@ -1,6 +1,7 @@ import java.util.List; public class BreakSchedule { + // #region Break Times Constants public static final int[] START_SMALL_BREAK = { 830, 1025, 1115, 1205, 1330, 1420, 1610, 1700, 1750 }; @@ -17,6 +18,7 @@ public class BreakSchedule { 940, 1525 }; + // #region Create Breaks Method public static Break[] createBreaks(int[] startTimes, int[] endTimes, List co2Data) { Break[] breaks = new Break[startTimes.length]; for (int i = 0; i < startTimes.length; i++) { @@ -30,4 +32,4 @@ public class BreakSchedule { } return breaks; } -} \ No newline at end of file +} diff --git a/src/Co2Data.class b/src/Co2Data.class new file mode 100644 index 0000000..8dc6a2a Binary files /dev/null and b/src/Co2Data.class differ diff --git a/src/Co2Data.java b/src/Co2Data.java index 3a8194d..7936293 100644 --- a/src/Co2Data.java +++ b/src/Co2Data.java @@ -6,10 +6,12 @@ import java.util.ArrayList; import java.util.List; public class Co2Data { + // #region Fields private Date date; private int time; private int co2Level; + // #region Constructor // Constructor public Co2Data(Date date, int co2Level) { this.date = date; @@ -17,6 +19,7 @@ public class Co2Data { this.time = date.getHour() * 100 + date.getMinute(); } + // #region Getters and Setters // Getters and Setters public Date getDate() { return date; @@ -42,6 +45,7 @@ public class Co2Data { this.time = time; } + // #region Data Fetching // Fetch and parse data from a CSV URL public static List getData(URL url) { List dataList = new ArrayList<>(); @@ -74,6 +78,7 @@ public class Co2Data { return dataList; } + // #region Data Parsing // Helper method to parse CSV data and create a Co2Data object private static Co2Data parseData(String line) { try { @@ -88,5 +93,4 @@ public class Co2Data { return null; } } - } diff --git a/src/Date.class b/src/Date.class new file mode 100644 index 0000000..70fddb7 Binary files /dev/null and b/src/Date.class differ diff --git a/src/Date.java b/src/Date.java index b3f4079..5e71ded 100644 --- a/src/Date.java +++ b/src/Date.java @@ -1,10 +1,12 @@ public class Date { + // #region Fields private int year; private int month; private int day; private int hour; private int minute; + // #region Constructors // Constructor to parse date string public Date(String dateStr) { String[] dateTime = dateStr.split(" "); @@ -33,6 +35,7 @@ public class Date { adjustForSwitzerlandTime(); } + // #region Time Adjustment // Adjust time for Switzerland timezone (UTC+1 or UTC+2 during daylight saving // time) private void adjustForSwitzerlandTime() { @@ -46,7 +49,7 @@ public class Date { } } - // Getter methods + // #region Getters public int getYear() { return year; } @@ -67,6 +70,7 @@ public class Date { return minute; } + // #region String Representation // Method to print date in a readable format public String toString() { return String.format("%04d-%02d-%02d %02d:%02d", year, month, day, hour, minute); diff --git a/src/Points.class b/src/Points.class new file mode 100644 index 0000000..1cef499 Binary files /dev/null and b/src/Points.class differ diff --git a/src/Points.java b/src/Points.java index 7fefe2b..7334c2a 100644 --- a/src/Points.java +++ b/src/Points.java @@ -4,7 +4,7 @@ public class Points { private int longerBreak; private int bonusPoints; - // #region Constructor + // #region Constructors public Points() { this.fiveMinuteBreak = 0; // Default initialization this.longerBreak = 0; // Default initialization @@ -73,7 +73,7 @@ public class Points { return fiveMinuteBreak + longerBreak + bonusPoints; } - // #region String Representation (Optional for debugging or output) + // #region String Representation @Override public String toString() { return String.format("Five Minute Break: %d, Longer Break: %d, Bonus Points: %d, Total: %d", diff --git a/src/Teacher.class b/src/Teacher.class new file mode 100644 index 0000000..d8883a6 Binary files /dev/null and b/src/Teacher.class differ diff --git a/src/Teacher.java b/src/Teacher.java index 495ddb6..6656de6 100644 --- a/src/Teacher.java +++ b/src/Teacher.java @@ -2,19 +2,19 @@ import java.util.HashMap; import java.util.Map; public class Teacher { + // #region Instance Attributes public static final Map nameMap = new HashMap<>(); private String shortName; private String name; - private int totalPoints; + private Points points; - // Constructor public Teacher(String shortName) { this.shortName = shortName; this.name = nameMap.get(shortName); - this.totalPoints = 0; + this.points = new Points(); } - // Getters + // #region Getters public String getShortName() { return shortName; } @@ -24,16 +24,19 @@ public class Teacher { } public int getTotalPoints() { - return totalPoints; + return this.points.getTotalPoints(); } - // Setters - public void setTotalPoints(int points) { - this.totalPoints = points; - } - - // Method to add points + // #region Public Methods public void addPoints(int smallBreakPoints, int longBreakPoints, int bonusPoints) { - this.totalPoints += smallBreakPoints + longBreakPoints + bonusPoints; + points.addBonusPoints(bonusPoints); + points.addFiveMinuteBreakPoints(smallBreakPoints); + points.addLongerBreakPoints(longBreakPoints); + } + + public String detailedPointString() { + return "5 minute points: " + this.points.getFiveMinuteBreak() + "\nlonger break points: " + + this.points.getLongerBreak() + "\nBonus points: " + this.points.getBonusPoints() + + "\nTotal points: " + this.points.getTotalPoints() + "\n-------------\n"; } } diff --git a/src/TimeTable.class b/src/TimeTable.class new file mode 100644 index 0000000..2c011d6 Binary files /dev/null and b/src/TimeTable.class differ diff --git a/src/TimeTable.java b/src/TimeTable.java index d304979..f0b7ffb 100644 --- a/src/TimeTable.java +++ b/src/TimeTable.java @@ -1,11 +1,14 @@ public class TimeTable { + // #region Attributes private String[][] shortTeacher; + // #region Constructor public TimeTable(int roomIndex) { shortTeacher = new String[11][5]; // 11 lessons, 5 weekdays initializeTimeTable(roomIndex); } + // #region Initialization Methods private void initializeTimeTable(int roomIndex) { switch (roomIndex) { case 0: // Room 37 @@ -70,6 +73,7 @@ public class TimeTable { }; } + // #region Public Methods public String getLesson(int lesson, int day) { if (lesson < 0 || lesson >= 11 || day < 0 || day >= 5) { throw new IllegalArgumentException("Invalid lesson or day");