Commented the code
This commit is contained in:
parent
cc1fb07f90
commit
7c6c6b2c2c
24 changed files with 55 additions and 24 deletions
BIN
bin/App.class
BIN
bin/App.class
Binary file not shown.
BIN
bin/Break.class
BIN
bin/Break.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
bin/Date.class
BIN
bin/Date.class
Binary file not shown.
BIN
bin/Points.class
BIN
bin/Points.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
src/App.class
Normal file
BIN
src/App.class
Normal file
Binary file not shown.
22
src/App.java
22
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) {
|
||||
|
|
BIN
src/Break.class
Normal file
BIN
src/Break.class
Normal file
Binary file not shown.
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
BIN
src/BreakSchedule.class
Normal file
BIN
src/BreakSchedule.class
Normal file
Binary file not shown.
|
@ -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> co2Data) {
|
||||
Break[] breaks = new Break[startTimes.length];
|
||||
for (int i = 0; i < startTimes.length; i++) {
|
||||
|
|
BIN
src/Co2Data.class
Normal file
BIN
src/Co2Data.class
Normal file
Binary file not shown.
|
@ -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<Co2Data> getData(URL url) {
|
||||
List<Co2Data> 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
BIN
src/Date.class
Normal file
BIN
src/Date.class
Normal file
Binary file not shown.
|
@ -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);
|
||||
|
|
BIN
src/Points.class
Normal file
BIN
src/Points.class
Normal file
Binary file not shown.
|
@ -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",
|
||||
|
|
BIN
src/Teacher.class
Normal file
BIN
src/Teacher.class
Normal file
Binary file not shown.
|
@ -2,19 +2,19 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
public class Teacher {
|
||||
// #region Instance Attributes
|
||||
public static final Map<String, String> 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";
|
||||
}
|
||||
}
|
||||
|
|
BIN
src/TimeTable.class
Normal file
BIN
src/TimeTable.class
Normal file
Binary file not shown.
|
@ -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");
|
||||
|
|
Loading…
Reference in a new issue