diff --git a/bin/App.class b/bin/App.class index 6b95327..4734521 100644 Binary files a/bin/App.class and b/bin/App.class differ diff --git a/src/App.java b/src/App.java index 4dcdccb..b112716 100644 --- a/src/App.java +++ b/src/App.java @@ -37,10 +37,8 @@ public class App { int breakPoints = minuteData.length; for (int i = 0; i < duration - 1; i++) { - if (minuteData[i] != null) { - if (minuteData[i].getCo2Level() < minuteData[i + 1].getCo2Level()) { - breakPoints--; - } + if (minuteData[i].getCo2Level() < minuteData[i + 1].getCo2Level()) { + breakPoints--; } } @@ -202,61 +200,65 @@ public class App { // #region main public static void main(String[] args) { + try { + System.out.println("Calculations in process. Please do not shut off..."); + initializeTeachers(); - System.out.println("Calculations in process. Please do not shut off..."); - initializeTeachers(); + for (int roomIndex = 0; roomIndex < ROOM_NUMBERS.length; roomIndex++) { + TimeTable timeTable = new TimeTable(roomIndex); - for (int roomIndex = 0; roomIndex < ROOM_NUMBERS.length; roomIndex++) { - TimeTable timeTable = new TimeTable(roomIndex); - - for (String date : DATES) { - try { - List tempData = Co2Data.getData(generateLink(ROOM_NUMBERS[roomIndex], date)); - if (tempData == null || tempData.isEmpty()) { - System.out - .println("No data available for " + date + " in Room" + (roomIndex + 37) + "."); - continue; - } - - Break[] shortBreaks = BreakSchedule.createBreaks( - BreakSchedule.START_SMALL_BREAK, BreakSchedule.END_SMALL_BREAK, tempData); - - Break[] longBreaks = BreakSchedule.createBreaks( - BreakSchedule.START_LONG_BREAK, BreakSchedule.END_LONG_BREAK, tempData); - - for (int i = 0; i < shortBreaks.length; i++) { - Teacher teacher = findTeacherForBreak(i, timeTable, Arrays.asList(DATES).indexOf(date)); - Teacher nextTeacher = findTeacherForBreak(i + 1, timeTable, - Arrays.asList(DATES).indexOf(date)); - if (teacher != null) { - if (nextTeacher == null) { - nextTeacher = teacher; - } - calculateBreakPoints(shortBreaks[i], teacher, nextTeacher); + for (String date : DATES) { + try { + List tempData = Co2Data.getData(generateLink(ROOM_NUMBERS[roomIndex], date)); + if (tempData == null || tempData.isEmpty()) { + System.out + .println("No data available for " + date + " in Room" + (roomIndex + 37) + "."); + continue; } - } - for (int i = 0; i < longBreaks.length; i++) { - Teacher teacher = findTeacherForBreak(i, timeTable, Arrays.asList(DATES).indexOf(date)); - Teacher nextTeacher = findTeacherForBreak(i + 1, timeTable, - Arrays.asList(DATES).indexOf(date)); - if (teacher != null) { - if (nextTeacher == null) { - nextTeacher = teacher; + Break[] shortBreaks = BreakSchedule.createBreaks( + BreakSchedule.START_SMALL_BREAK, BreakSchedule.END_SMALL_BREAK, tempData); + + Break[] longBreaks = BreakSchedule.createBreaks( + BreakSchedule.START_LONG_BREAK, BreakSchedule.END_LONG_BREAK, tempData); + + for (int i = 0; i < shortBreaks.length; i++) { + Teacher teacher = findTeacherForBreak(i, timeTable, Arrays.asList(DATES).indexOf(date)); + Teacher nextTeacher = findTeacherForBreak(i + 1, timeTable, + Arrays.asList(DATES).indexOf(date)); + if (teacher != null) { + if (nextTeacher == null) { + nextTeacher = teacher; + } + calculateBreakPoints(shortBreaks[i], teacher, nextTeacher); } - calculateBreakPoints(longBreaks[i], teacher, nextTeacher); } + + for (int i = 0; i < longBreaks.length; i++) { + Teacher teacher = findTeacherForBreak(i, timeTable, Arrays.asList(DATES).indexOf(date)); + Teacher nextTeacher = findTeacherForBreak(i + 1, timeTable, + Arrays.asList(DATES).indexOf(date)); + if (teacher != null) { + if (nextTeacher == null) { + nextTeacher = teacher; + } + calculateBreakPoints(longBreaks[i], teacher, nextTeacher); + } + } + } catch (MalformedURLException e) { + System.out.println("Error processing data for date: " + date + ". " + e); } - } catch (MalformedURLException e) { - System.out.println("Error processing data for date: " + date + ". " + e); } } + + sortTeachers(); + printTeachers(false); + interactWithUser(); + + } catch (Exception e) { + System.out.println("Fatal error: " + e.getMessage()); + } finally { + scanner.close(); } - - sortTeachers(); - printTeachers(false); - interactWithUser(); - - scanner.close(); } }