Migration
This commit is contained in:
parent
876fa94fda
commit
57a93bc812
25 changed files with 763 additions and 2 deletions
7
.vscode/settings.json
vendored
Normal file
7
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"java.project.sourcePaths": ["src"],
|
||||
"java.project.outputPath": "bin",
|
||||
"java.project.referencedLibraries": [
|
||||
"lib/**/*.jar"
|
||||
]
|
||||
}
|
19
README.md
19
README.md
|
@ -1,3 +1,18 @@
|
|||
# co2DataProject
|
||||
## Getting Started
|
||||
|
||||
Hell on earth
|
||||
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
|
||||
|
||||
## Folder Structure
|
||||
|
||||
The workspace contains two folders by default, where:
|
||||
|
||||
- `src`: the folder to maintain sources
|
||||
- `lib`: the folder to maintain dependencies
|
||||
|
||||
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
|
||||
|
||||
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
|
||||
|
||||
## Dependency Management
|
||||
|
||||
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
|
||||
|
|
BIN
bin/App.class
Normal file
BIN
bin/App.class
Normal file
Binary file not shown.
BIN
bin/Break.class
Normal file
BIN
bin/Break.class
Normal file
Binary file not shown.
BIN
bin/BreakSchedule.class
Normal file
BIN
bin/BreakSchedule.class
Normal file
Binary file not shown.
BIN
bin/Co2Data.class
Normal file
BIN
bin/Co2Data.class
Normal file
Binary file not shown.
BIN
bin/Date.class
Normal file
BIN
bin/Date.class
Normal file
Binary file not shown.
BIN
bin/Points.class
Normal file
BIN
bin/Points.class
Normal file
Binary file not shown.
BIN
bin/Teacher.class
Normal file
BIN
bin/Teacher.class
Normal file
Binary file not shown.
BIN
bin/Time.class
Normal file
BIN
bin/Time.class
Normal file
Binary file not shown.
BIN
bin/TimeTable.class
Normal file
BIN
bin/TimeTable.class
Normal file
Binary file not shown.
BIN
src/App.class
Normal file
BIN
src/App.class
Normal file
Binary file not shown.
203
src/App.java
Normal file
203
src/App.java
Normal file
|
@ -0,0 +1,203 @@
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class App {
|
||||
// #region app constants
|
||||
private static final Scanner scanner = new Scanner(System.in);
|
||||
private static final Teacher[] teachers = new Teacher[Teacher.nameMap.size()];
|
||||
|
||||
// Room channel numbers
|
||||
private static final int ROOM_39_NUMBER = 1521262;
|
||||
private static final int ROOM_38_NUMBER = 1364580;
|
||||
private static final int ROOM_37_NUMBER = 1521263;
|
||||
|
||||
// Date and time constants for Start and End Dates
|
||||
private static final String START_DATE = "2024-11-04";
|
||||
private static final String END_DATE = "2024-11-08";
|
||||
|
||||
// #region Initialization
|
||||
|
||||
public static String generateLink(int channelNumber, String date, String startTime, String endTime) {
|
||||
String baseUrl = "https://api.thingspeak.com/channels/";
|
||||
String formattedStartDateTime = date + " " + startTime;
|
||||
String formattedEndDateTime = date + " " + endTime;
|
||||
|
||||
return baseUrl + channelNumber + "/feeds.csv?start=" + formattedStartDateTime.replace(" ", "%20")
|
||||
+ "&end=" + formattedEndDateTime.replace(" ", "%20"); // %20 --> " "
|
||||
|
||||
}
|
||||
|
||||
private static double getDataAverageForMinute(int minute, int hour, int number, String date) {
|
||||
// get the url
|
||||
String startTime = "";
|
||||
if (hour < 10) {
|
||||
startTime += "0";
|
||||
}
|
||||
startTime += String.valueOf(hour);
|
||||
startTime += ":";
|
||||
if (minute < 10) {
|
||||
startTime += "0";
|
||||
}
|
||||
startTime += String.valueOf(minute);
|
||||
String calcStarttime = startTime + ":00";
|
||||
String calcEndTime = startTime + "59";
|
||||
|
||||
String url = generateLink(number, date, calcStarttime, calcEndTime);
|
||||
|
||||
double averageCO2 = 0.0;
|
||||
List<Co2Data> co2DataList = Co2Data.getData(url);
|
||||
for (Co2Data co2Data : co2DataList) {
|
||||
averageCO2 += co2Data.getCo2Level();
|
||||
}
|
||||
|
||||
return averageCO2 / co2DataList.size(); // Example CO2 average level
|
||||
}
|
||||
|
||||
private static void calculateBreakPoints(double[] minuteData, Break calcBreak, Teacher teacher) {
|
||||
int duration = calcBreak.getEnd().getMinute() - calcBreak.getStart().getMinute();
|
||||
int breakPoints = minuteData.length;
|
||||
if (duration == minuteData.length) {
|
||||
for (int i = 0; i < duration; i++) {
|
||||
if (minuteData[i] < minuteData[i + 1]) {
|
||||
breakPoints--;
|
||||
}
|
||||
}
|
||||
} else
|
||||
System.out.println("Unexpected error");
|
||||
if (duration > 5) {
|
||||
teacher.addPoints(0, breakPoints, 0);
|
||||
} else {
|
||||
teacher.addPoints(breakPoints, 0, 0);
|
||||
}
|
||||
|
||||
// check if next lesson is lunch another teacher or the same and plan
|
||||
// accordingly
|
||||
|
||||
}
|
||||
|
||||
private static void initializeTeachers() {
|
||||
int index = 0;
|
||||
for (String initial : Teacher.nameMap.keySet()) {
|
||||
Teacher teacher = new Teacher(initial);
|
||||
Points points = new Points(); // Initialize Points object for each teacher
|
||||
teacher.setPoints(points.getLongerBreak(), points.getBonusPoints(), points.getFiveMinuteBreak());
|
||||
teachers[index++] = teacher;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// #region User Interaction
|
||||
private static int getUserInput(String textOutput) {
|
||||
System.out.println(textOutput);
|
||||
while (true) {
|
||||
if (scanner.hasNextInt()) {
|
||||
return scanner.nextInt();
|
||||
}
|
||||
scanner.next(); // Clear invalid input
|
||||
}
|
||||
}
|
||||
|
||||
// #region Explanation
|
||||
private static void printExplanation() {
|
||||
System.out.println("Point calculation explanation:");
|
||||
System.out.println("1. Up to 5 points for keeping the window open during a small pause.");
|
||||
System.out.println("2. Up to 10 points for long pauses, depending on window usage.");
|
||||
System.out.println("3. 5 bonus points for teacher switches in classrooms.");
|
||||
}
|
||||
|
||||
// #region shutdown
|
||||
private static void printShutDown() {
|
||||
System.out.println("Shutting down...");
|
||||
for (int i = 3; i > 0; i--) {
|
||||
System.out.print(i + "...");
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// #TODO: remove this before hand-in deadline
|
||||
public static void debbugingValueLists(List<Co2Data> data) {
|
||||
// Debugging co2Data
|
||||
int index = 0;
|
||||
for (Co2Data a : data) {
|
||||
System.out.println(a.toString());
|
||||
index++;
|
||||
}
|
||||
|
||||
System.out.println("-----------------");
|
||||
System.out.println(index);
|
||||
}
|
||||
|
||||
// #TODO
|
||||
// #region Print & sort
|
||||
private static void sortTeachers() {
|
||||
// Sorting teachers by total points (implement sorting logic based on points)
|
||||
Arrays.sort(teachers,
|
||||
(a, b) -> Integer.compare(b.getPoints().getTotalPoints(), a.getPoints().getTotalPoints()));
|
||||
}
|
||||
|
||||
private static void printTeachers() {
|
||||
int rank = 1;
|
||||
int previousPoints = -1;
|
||||
int currentRank = 1;
|
||||
|
||||
for (int i = 0; i < teachers.length; i++) {
|
||||
Teacher teacher = teachers[i];
|
||||
int teacherPoints = teacher.getPoints().getTotalPoints(); // Assuming points are available in getPoints()
|
||||
|
||||
if (teacherPoints == previousPoints) {
|
||||
System.out.println(currentRank + ". " + teacher.getName() + " " + teacherPoints);
|
||||
} else {
|
||||
if (i > 0) {
|
||||
rank += (i - (currentRank - 1));
|
||||
}
|
||||
currentRank = rank;
|
||||
System.out.println(rank + ". " + teacher.getName() + " " + teacherPoints);
|
||||
}
|
||||
|
||||
previousPoints = teacherPoints;
|
||||
}
|
||||
}
|
||||
|
||||
// #region Main
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Calculations in process please do not shut off...");
|
||||
initializeTeachers();
|
||||
sortTeachers();
|
||||
printTeachers();
|
||||
for (int classrooms = 0; classrooms < 3; classrooms++) {
|
||||
for (int weekday = 0; weekday < 5; weekday++) {
|
||||
// get the url and data
|
||||
// calculate points
|
||||
}
|
||||
}
|
||||
// Loop threw each day with a specific classroom and after the weekdays are over
|
||||
// go to the next of the 3 classroms
|
||||
// go threw every break calculate the point and give them to the teacher
|
||||
// directly
|
||||
// remember the point class
|
||||
// breakShedule needed
|
||||
|
||||
while (true) {
|
||||
int userInput = getUserInput(
|
||||
"Do you want to see how the points were calculated? (Yes 1, No 0; anything is an error)");
|
||||
if (userInput == 1) {
|
||||
printExplanation();
|
||||
// add a more detailed listing of the teacher since points can be broken down
|
||||
// further
|
||||
printShutDown();
|
||||
break;
|
||||
} else if (userInput == 0) {
|
||||
printShutDown();
|
||||
break;
|
||||
} else {
|
||||
System.out.println("Invalid input. Please enter 1 for Yes or 0 for No.");
|
||||
}
|
||||
}
|
||||
scanner.close();
|
||||
}
|
||||
}
|
56
src/Break.java
Normal file
56
src/Break.java
Normal file
|
@ -0,0 +1,56 @@
|
|||
public class Break {
|
||||
private Time start;
|
||||
private Time end;
|
||||
|
||||
public Break(Time start, Time end) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
public Time getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
public void setStart(Time start) {
|
||||
this.start = start;
|
||||
}
|
||||
|
||||
public Time getEnd() {
|
||||
return end;
|
||||
}
|
||||
|
||||
public void setEnd(Time end) {
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a Thingspeak API link based on channel number, date, and break
|
||||
* period.
|
||||
*
|
||||
* @param channelNumber The Thingspeak channel number.
|
||||
* @param date The date in format "YYYY-MM-DD".
|
||||
* @param breakPeriod The Break object containing start and end times.
|
||||
* @return A formatted URL for fetching data from the Thingspeak API.
|
||||
*/
|
||||
public static String generateLink(int channelNumber, String date, Break breakPeriod) {
|
||||
String baseUrl = "https://api.thingspeak.com/channels/";
|
||||
String formattedStartDateTime = date + " " + breakPeriod.getStart().toString();
|
||||
String formattedEndDateTime = date + " " + breakPeriod.getEnd().toString();
|
||||
|
||||
return baseUrl + channelNumber + "/feeds.csv?start=" + formattedStartDateTime.replace(" ", "%20")
|
||||
+ "&end=" + formattedEndDateTime.replace(" ", "%20");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Example usage
|
||||
Time start = Time.valueOf("00:00:00");
|
||||
Time end = Time.valueOf("23:59:59");
|
||||
Break breakPeriod = new Break(start, end);
|
||||
|
||||
String date = "2024-11-17";
|
||||
int channelNumber = 1364580;
|
||||
|
||||
String link = Break.generateLink(channelNumber, date, breakPeriod);
|
||||
System.out.println(link);
|
||||
}
|
||||
}
|
47
src/BreakSchedule.java
Normal file
47
src/BreakSchedule.java
Normal file
|
@ -0,0 +1,47 @@
|
|||
public class BreakSchedule {
|
||||
private static final String[] START_SMALL_BREAK = {
|
||||
"8:30", "10:25", "11:15", "12:05", "13:30", "14:20", "16:10", "17:00", "17:50"
|
||||
};
|
||||
|
||||
private static final String[] END_SMALL_BREAK = {
|
||||
"8:35", "10:30", "11:20", "12:10", "13:35", "14:25", "16:15", "17:05", "17:55"
|
||||
};
|
||||
|
||||
private static final String[] START_LONG_BREAK = {
|
||||
"9:20", "15:10"
|
||||
};
|
||||
|
||||
private static final String[] END_LONG_BREAK = {
|
||||
"9:40", "15:25"
|
||||
};
|
||||
|
||||
private static final Break[] SMALL_BREAKS;
|
||||
private static final Break[] LONG_BREAKS;
|
||||
|
||||
static {
|
||||
SMALL_BREAKS = createBreaks(START_SMALL_BREAK, END_SMALL_BREAK);
|
||||
LONG_BREAKS = createBreaks(START_LONG_BREAK, END_LONG_BREAK);
|
||||
}
|
||||
|
||||
private static Break[] createBreaks(String[] startTimes, String[] endTimes) {
|
||||
Break[] breaks = new Break[startTimes.length];
|
||||
for (int i = 0; i < startTimes.length; i++) {
|
||||
// Append ":00" to include seconds
|
||||
String startTimeWithSeconds = startTimes[i];
|
||||
String endTimeWithSeconds = endTimes[i];
|
||||
|
||||
Time start = Time.valueOf(startTimeWithSeconds);
|
||||
Time end = Time.valueOf(endTimeWithSeconds);
|
||||
breaks[i] = new Break(start, end);
|
||||
}
|
||||
return breaks;
|
||||
}
|
||||
|
||||
public static Break[] getSmallBreaks() {
|
||||
return SMALL_BREAKS;
|
||||
}
|
||||
|
||||
public static Break[] getLongBreaks() {
|
||||
return LONG_BREAKS;
|
||||
}
|
||||
}
|
BIN
src/Co2Data.class
Normal file
BIN
src/Co2Data.class
Normal file
Binary file not shown.
88
src/Co2Data.java
Normal file
88
src/Co2Data.java
Normal file
|
@ -0,0 +1,88 @@
|
|||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class Co2Data {
|
||||
private Date date;
|
||||
private int co2Level;
|
||||
|
||||
// Constructor
|
||||
public Co2Data(Date date, int co2Level) {
|
||||
this.date = date;
|
||||
this.co2Level = co2Level;
|
||||
}
|
||||
|
||||
// Getters and Setters
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public int getCo2Level() {
|
||||
return co2Level;
|
||||
}
|
||||
|
||||
public void setCo2Level(int co2Level) {
|
||||
this.co2Level = co2Level;
|
||||
}
|
||||
|
||||
// Fetch and parse data from a CSV URL
|
||||
public static List<Co2Data> getData(String csvURL) {
|
||||
List<Co2Data> dataList = new ArrayList<>();
|
||||
|
||||
try {
|
||||
URL url = new URL(csvURL);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setRequestProperty("Accept", "text/csv");
|
||||
|
||||
if (conn.getResponseCode() != 200) {
|
||||
throw new RuntimeException("Failed : HTTP Error code : " + conn.getResponseCode());
|
||||
}
|
||||
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
br.readLine(); // Skip header line
|
||||
|
||||
String output;
|
||||
while ((output = br.readLine()) != null) {
|
||||
Co2Data data = parseData(output);
|
||||
if (data != null) {
|
||||
dataList.add(data);
|
||||
}
|
||||
}
|
||||
conn.disconnect();
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error in data fetching: " + e);
|
||||
}
|
||||
|
||||
return dataList;
|
||||
}
|
||||
|
||||
// Helper method to parse CSV data and create a Co2Data object
|
||||
private static Co2Data parseData(String line) {
|
||||
try {
|
||||
String[] parts = line.split(",");
|
||||
String dateStr = parts[0].trim(); // assuming date is in the first column
|
||||
int co2Level = Integer.parseInt(parts[1].trim()); // assuming CO2 level is in the second column
|
||||
|
||||
// Convert the date string into a Date object (assumes CSV date format is
|
||||
// yyyy-MM-dd HH:mm:ss)
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Date date = sdf.parse(dateStr);
|
||||
|
||||
return new Co2Data(date, co2Level);
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error parsing data line: " + e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
BIN
src/Date.class
Normal file
BIN
src/Date.class
Normal file
Binary file not shown.
74
src/Date.java
Normal file
74
src/Date.java
Normal file
|
@ -0,0 +1,74 @@
|
|||
public class Date {
|
||||
private int year;
|
||||
private int month;
|
||||
private int day;
|
||||
private int hour;
|
||||
private int minute;
|
||||
|
||||
// Constructor to parse date string
|
||||
public Date(String dateStr) {
|
||||
String[] dateTime = dateStr.split(" ");
|
||||
String[] dateParts = dateTime[0].split("-");
|
||||
String[] timeParts = dateTime[1].split(":");
|
||||
|
||||
this.year = Integer.parseInt(dateParts[0]);
|
||||
this.month = Integer.parseInt(dateParts[1]);
|
||||
this.day = Integer.parseInt(dateParts[2]);
|
||||
this.hour = Integer.parseInt(timeParts[0]);
|
||||
this.minute = Integer.parseInt(timeParts[1]);
|
||||
|
||||
// Adjust for Switzerland time
|
||||
adjustForSwitzerlandTime();
|
||||
}
|
||||
|
||||
// Constructor to create date with fixed numeric values
|
||||
public Date(int year, int month, int day, int hour, int minute) {
|
||||
this.year = year;
|
||||
this.month = month;
|
||||
this.day = day;
|
||||
this.hour = hour;
|
||||
this.minute = minute;
|
||||
|
||||
// Adjust for Switzerland time
|
||||
adjustForSwitzerlandTime();
|
||||
}
|
||||
|
||||
// Adjust time for Switzerland timezone (UTC+1 or UTC+2 during daylight saving
|
||||
// time)
|
||||
private void adjustForSwitzerlandTime() {
|
||||
// Switzerland time adjustment logic (simplified version)
|
||||
// For simplicity, this doesn't handle daylight saving time changes but adjusts
|
||||
// based on UTC+1
|
||||
this.hour += 1; // Assuming fixed UTC+1 offset for simplicity
|
||||
if (this.hour >= 24) {
|
||||
this.hour -= 24;
|
||||
this.day += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Getter methods
|
||||
public int getYear() {
|
||||
return year;
|
||||
}
|
||||
|
||||
public int getMonth() {
|
||||
return month;
|
||||
}
|
||||
|
||||
public int getDay() {
|
||||
return day;
|
||||
}
|
||||
|
||||
public int getHour() {
|
||||
return hour;
|
||||
}
|
||||
|
||||
public int getMinute() {
|
||||
return minute;
|
||||
}
|
||||
|
||||
// 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.
82
src/Points.java
Normal file
82
src/Points.java
Normal file
|
@ -0,0 +1,82 @@
|
|||
public class Points {
|
||||
// #region Fields
|
||||
private int fiveMinuteBreak;
|
||||
private int longerBreak;
|
||||
private int bonusPoints;
|
||||
|
||||
// #region Constructor
|
||||
public Points() {
|
||||
this.fiveMinuteBreak = 0; // Default initialization
|
||||
this.longerBreak = 0; // Default initialization
|
||||
this.bonusPoints = 0; // Default initialization
|
||||
}
|
||||
|
||||
public Points(int fiveMinuteBreak, int longerBreak, int bonusPoints) {
|
||||
this.fiveMinuteBreak = fiveMinuteBreak >= 0 ? fiveMinuteBreak : 0; // Validate
|
||||
this.longerBreak = longerBreak >= 0 ? longerBreak : 0; // Validate
|
||||
this.bonusPoints = bonusPoints >= 0 ? bonusPoints : 0; // Validate
|
||||
}
|
||||
|
||||
// Copy constructor to duplicate an existing Points object
|
||||
public Points(Points points) {
|
||||
this.fiveMinuteBreak = points.fiveMinuteBreak;
|
||||
this.longerBreak = points.longerBreak;
|
||||
this.bonusPoints = points.bonusPoints;
|
||||
}
|
||||
|
||||
// #region Getters and Setters
|
||||
public int getFiveMinuteBreak() {
|
||||
return fiveMinuteBreak;
|
||||
}
|
||||
|
||||
public void setFiveMinuteBreak(int fiveMinuteBreak) {
|
||||
this.fiveMinuteBreak = Math.max(fiveMinuteBreak, 0); // Ensure no negative points
|
||||
}
|
||||
|
||||
public int getLongerBreak() {
|
||||
return longerBreak;
|
||||
}
|
||||
|
||||
public void setLongerBreak(int longerBreak) {
|
||||
this.longerBreak = Math.max(longerBreak, 0); // Ensure no negative points
|
||||
}
|
||||
|
||||
public int getBonusPoints() {
|
||||
return bonusPoints;
|
||||
}
|
||||
|
||||
public void setBonusPoints(int bonusPoints) {
|
||||
this.bonusPoints = Math.max(bonusPoints, 0); // Ensure no negative points
|
||||
}
|
||||
|
||||
// #region Points Adjustment Methods
|
||||
public void addFiveMinuteBreakPoints(int points) {
|
||||
if (points > 0) {
|
||||
this.fiveMinuteBreak += points;
|
||||
}
|
||||
}
|
||||
|
||||
public void addLongerBreakPoints(int points) {
|
||||
if (points > 0) {
|
||||
this.longerBreak += points;
|
||||
}
|
||||
}
|
||||
|
||||
public void addBonusPoints(int points) {
|
||||
if (points > 0) {
|
||||
this.bonusPoints += points;
|
||||
}
|
||||
}
|
||||
|
||||
// #region Total Points Calculation
|
||||
public int getTotalPoints() {
|
||||
return fiveMinuteBreak + longerBreak + bonusPoints;
|
||||
}
|
||||
|
||||
// #region String Representation (Optional for debugging or output)
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("Five Minute Break: %d, Longer Break: %d, Bonus Points: %d, Total: %d",
|
||||
fiveMinuteBreak, longerBreak, bonusPoints, getTotalPoints());
|
||||
}
|
||||
}
|
BIN
src/Teacher.class
Normal file
BIN
src/Teacher.class
Normal file
Binary file not shown.
73
src/Teacher.java
Normal file
73
src/Teacher.java
Normal file
|
@ -0,0 +1,73 @@
|
|||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Teacher {
|
||||
// #region Fields
|
||||
private String name;
|
||||
private Map<String, String[]> timetable = new HashMap<>(); // Map of Day -> Teachers in class for that day
|
||||
private Points points; // Points field to store teacher's points
|
||||
|
||||
public static final Map<String, String> nameMap = new HashMap<>();
|
||||
|
||||
// #region Initialization
|
||||
static {
|
||||
// Mapping short names to full teacher names
|
||||
nameMap.put("Hm", "Hummel");
|
||||
nameMap.put("Bd", "Bender");
|
||||
nameMap.put("Bu", "Burger");
|
||||
nameMap.put("Cg", "Chung");
|
||||
nameMap.put("Do", "Doe");
|
||||
nameMap.put("Eh", "Ehrlich");
|
||||
nameMap.put("Fh", "Fischer");
|
||||
nameMap.put("Gi", "Giordano");
|
||||
nameMap.put("Gr", "Graham");
|
||||
nameMap.put("Hi", "Higgins");
|
||||
nameMap.put("Kg", "Kang");
|
||||
nameMap.put("Kh", "Khan");
|
||||
nameMap.put("Lz", "Lozano");
|
||||
nameMap.put("Lu", "Lund");
|
||||
nameMap.put("Or", "Ortega");
|
||||
nameMap.put("Re", "Reyes");
|
||||
nameMap.put("Se", "Seng");
|
||||
nameMap.put("Ts", "Tanaka");
|
||||
nameMap.put("Vt", "Vetter");
|
||||
nameMap.put("Zu", "Zuniga");
|
||||
}
|
||||
|
||||
// #region Constructor
|
||||
public Teacher(String name) {
|
||||
// Use the short name to find the full name from the nameMap
|
||||
this.name = nameMap.getOrDefault(name, "Unknown");
|
||||
this.points = new Points(); // Initialize Points object when Teacher is created
|
||||
}
|
||||
|
||||
// #region Getters and Setters
|
||||
public String getName() {
|
||||
return name; // Return the teacher's full name
|
||||
}
|
||||
|
||||
public Map<String, String[]> getTimetable() {
|
||||
return Collections.unmodifiableMap(timetable); // Return an unmodifiable view of the timetable
|
||||
}
|
||||
|
||||
public Points getPoints() {
|
||||
return points; // Return the Points object associated with the teacher
|
||||
}
|
||||
|
||||
public void setPoints(int fiveMinute, int tenMinutes, int bonusPoints) {
|
||||
this.points.setFiveMinuteBreak(fiveMinute);
|
||||
this.points.setLongerBreak(tenMinutes);
|
||||
this.points.setBonusPoints(bonusPoints);
|
||||
}
|
||||
|
||||
public void addPoints(int fiveMinute, int tenMinutes, int bonusPoints) {
|
||||
this.points.addFiveMinuteBreakPoints(fiveMinute);
|
||||
this.points.addLongerBreakPoints(tenMinutes);
|
||||
this.points.addBonusPoints(bonusPoints);
|
||||
}
|
||||
|
||||
public int getTotalPoints() {
|
||||
return this.points.getTotalPoints();
|
||||
}
|
||||
}
|
37
src/Time.java
Normal file
37
src/Time.java
Normal file
|
@ -0,0 +1,37 @@
|
|||
public class Time {
|
||||
private int hour;
|
||||
private int minute;
|
||||
|
||||
public Time(int hour, int minute) {
|
||||
if (hour >= 1 && hour <= 24 && minute >= 1 && minute <= 60) {
|
||||
this.hour = hour;
|
||||
this.minute = minute;
|
||||
} else {
|
||||
System.out.println("Failed to initialize the hour");
|
||||
}
|
||||
}
|
||||
|
||||
public int getHour() {
|
||||
return hour;
|
||||
}
|
||||
|
||||
public void setHour(int hour) {
|
||||
this.hour = hour;
|
||||
}
|
||||
|
||||
public int getMinute() {
|
||||
return minute;
|
||||
}
|
||||
|
||||
public void setMinute(int minute) {
|
||||
this.minute = minute;
|
||||
}
|
||||
|
||||
public static Time valueOf(String time) {
|
||||
String[] parts = time.split(":");
|
||||
int hour = Integer.parseInt(parts[0]);
|
||||
int minute = Integer.parseInt(parts[1]);
|
||||
Time returnValue = new Time(hour, minute);
|
||||
return returnValue;
|
||||
}
|
||||
}
|
79
src/TimeTable.java
Normal file
79
src/TimeTable.java
Normal file
|
@ -0,0 +1,79 @@
|
|||
public class TimeTable {
|
||||
private String[][] shortTeacher;
|
||||
|
||||
public TimeTable(int roomIndex) {
|
||||
shortTeacher = new String[11][5]; // 11 lessons, 5 weekdays
|
||||
initializeTimeTable(roomIndex);
|
||||
}
|
||||
|
||||
private void initializeTimeTable(int roomIndex) {
|
||||
switch (roomIndex) {
|
||||
case 0: // Room 37
|
||||
fillRoom37();
|
||||
break;
|
||||
case 1: // Room 38
|
||||
fillRoom38();
|
||||
break;
|
||||
case 2: // Room 39
|
||||
fillRoom39();
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid room index");
|
||||
}
|
||||
}
|
||||
|
||||
private void fillRoom37() {
|
||||
shortTeacher = new String[][] {
|
||||
{ "Hm", "Ts", "Lu", "Gi", "Kp" },
|
||||
{ "Hm", "Ts", "Lu", "Gi", "KP" },
|
||||
{ "Hi", "Ts", "Lu", "Ba", "Or" },
|
||||
{ "Hm", "Ts", "Lu", "Ba", "Vt" },
|
||||
{ "Hm", "Le", "Cg", "Ba", "Vt" },
|
||||
{ "Lunch", "Lunch", "Lunch", "Lunch", "Lunch" },
|
||||
{ "Bd", "Lunch", "Se", "Bd", "Lunch" },
|
||||
{ "Gi", "Fh", "Se", "Du", "Du" },
|
||||
{ "Gi", "Fh", "Se", "Lz", "Du" },
|
||||
{ "Ts", "Fh", "Se", "Lz", "Du" },
|
||||
{ "Ts", "Fh", "Se", "", "" }
|
||||
};
|
||||
}
|
||||
|
||||
private void fillRoom38() {
|
||||
shortTeacher = new String[][] {
|
||||
{ "Bz", "Kg", "Cg", "Do", "" },
|
||||
{ "Bz", "Kg", "Cg", "Do", "Hu" },
|
||||
{ "Bz", "Eh", "Cg", "Gr", "Ge" },
|
||||
{ "Bz", "Re", "Cg", "Gr", "Eh" },
|
||||
{ "Bz", "Re", "Es", "Or", "Eh" },
|
||||
{ "Lunch", "Lunch", "Lunch", "Lunch", "Lunch" },
|
||||
{ "Lunch", "Lunch", "Lunch", "Lunch", "Bu" },
|
||||
{ "Hn", "Bt", "Cg", "Bu", "Eh" },
|
||||
{ "Hn", "Kh", "Cg", "Bu", "Eh" },
|
||||
{ "Bu", "Kh", "", "Zu", "" },
|
||||
{ "Hn", "", "", "", "" }
|
||||
};
|
||||
}
|
||||
|
||||
private void fillRoom39() {
|
||||
shortTeacher = new String[][] {
|
||||
{ "Bd", "Do", "Cg", "Bd", "Gi" },
|
||||
{ "Bd", "Do", "Cg", "Bd", "Gi" },
|
||||
{ "Bd", "Zu", "Cg", "Bd", "Gr" },
|
||||
{ "Bd", "Zu", "Cg", "Bd", "Gr" },
|
||||
{ "Bd", "Zu", "Bu", "Or", "Gi" },
|
||||
{ "Lunch", "Lunch", "Lunch", "Lunch", "Lunch" },
|
||||
{ "Lunch", "Lunch", "Lunch", "Lunch", "Lunch" },
|
||||
{ "Lu", "Se", "Gi", "Le", "Hi" },
|
||||
{ "Lu", "Se", "Gi", "Le", "Hi" },
|
||||
{ "Lu", "Se", "Gi", "Le", "Hi" },
|
||||
{ "Lu", "Se", "Gi", "", "" }
|
||||
};
|
||||
}
|
||||
|
||||
public String getLesson(int lesson, int day) {
|
||||
if (lesson < 0 || lesson >= 11 || day < 0 || day >= 5) {
|
||||
throw new IllegalArgumentException("Invalid lesson or day");
|
||||
}
|
||||
return shortTeacher[lesson][day];
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue