Project
This commit is contained in:
parent
c317cd6227
commit
390b59addf
8 changed files with 254 additions and 60 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,47 +1,141 @@
|
|||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class App {
|
||||
// Fetch data for rooms
|
||||
private List<Data> room39Data = Data.getData("https://api.thingspeak.com/channels/1521262/feeds.csv", 39);
|
||||
private List<Data> room38Data = Data.getData("https://api.thingspeak.com/channels/1364580/feeds.csv", 38);
|
||||
private List<Data> room37Data = Data.getData("https://api.thingspeak.com/channels/1521263/feeds.csv", 37);
|
||||
private static final Scanner scanner = new Scanner(System.in); // Initialize the scanner
|
||||
|
||||
// Constants for rooms and timetable dimensions
|
||||
private static final int ROOM_COUNT = 3;
|
||||
private static final int DAY_COUNT = 5;
|
||||
private static final int LESSON_COUNT = 12;
|
||||
|
||||
// Data sources for different rooms
|
||||
private static final List<Data> room39Data = Data.getData("https://api.thingspeak.com/channels/1521262/feeds.csv",
|
||||
39);
|
||||
private static final List<Data> room38Data = Data.getData("https://api.thingspeak.com/channels/1364580/feeds.csv",
|
||||
38);
|
||||
private static final List<Data> room37Data = Data.getData("https://api.thingspeak.com/channels/1521263/feeds.csv",
|
||||
37);
|
||||
|
||||
// Time table
|
||||
// [Room 37 (0), 38 (1), or 39 (2)][Day 0-4][Lesson slot 0-11]
|
||||
static Lesson[][][] timeTable = new Lesson[3][5][12];
|
||||
public static final Lesson[][][] timeTable = new Lesson[ROOM_COUNT][DAY_COUNT][LESSON_COUNT];
|
||||
|
||||
public static void main(String[] args) {
|
||||
fillInTimeTable();
|
||||
// Teacher initials and array
|
||||
private static final String[] TEACHER_INITIALS = {
|
||||
"Bä", "Bd", "Bu", "Cg", "Di", "Do", "Eh", "Es", "Fh", "Gi",
|
||||
"Gr", "Hm", "Hi", "Kg", "Kh", "Lz", "Lu", "Or", "Re", "Se",
|
||||
"Ts", "Vt", "Zu"
|
||||
};
|
||||
private static final Teacher[] teachers = new Teacher[TEACHER_INITIALS.length];
|
||||
|
||||
// Display filled timetable for verification
|
||||
for (int room = 0; room < timeTable.length; room++) {
|
||||
for (int day = 0; day < timeTable[room].length; day++) {
|
||||
System.out.println("Room " + (room + 37) + ", Day " + (day + 1) + ":");
|
||||
for (int lesson = 0; lesson < timeTable[room][day].length; lesson++) {
|
||||
Lesson lessonData = timeTable[room][day][lesson];
|
||||
if (lessonData != null) {
|
||||
System.out.println(" Lesson " + (lesson + 1) + ": " + lessonData);
|
||||
} else {
|
||||
System.out.println(" Lesson " + (lesson + 1) + ": No Lesson");
|
||||
}
|
||||
}
|
||||
}
|
||||
// Initialization of teachers
|
||||
private static void initializeTeachers() {
|
||||
for (int i = 0; i < teachers.length; i++) {
|
||||
teachers[i] = new Teacher(TEACHER_INITIALS[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Filling in the timetable
|
||||
private static void fillInTimeTable() {
|
||||
// Fill Room 37 timetable
|
||||
FillTable.fillRoom37TimeTable();
|
||||
|
||||
// Fill Room 38 timetable
|
||||
FillTable.fillRoom38TimeTable();
|
||||
|
||||
// Fill Room 39 timetable
|
||||
FillTable.fillRoom39TimeTable();
|
||||
|
||||
FillTable.fill37TimeTable();
|
||||
FillTable.fill38TimeTable();
|
||||
FillTable.fill39TimeTable();
|
||||
}
|
||||
|
||||
private static void fillRoom37TimeTable() {
|
||||
// Calculate points based on criteria
|
||||
private static void calculatePoints() {
|
||||
// TODO: Implement point calculation logic based on specific criteria.
|
||||
// Example: If a teacher opens the window during a small break (entire break 5
|
||||
// points - can
|
||||
// be reduced by the amount the window was open).
|
||||
// Maximum points for a long break: 10 points.
|
||||
// Plus 5 bonus points if the teachers are switching after.
|
||||
for (Teacher teacher : teachers) {
|
||||
// Implement logic to calculate points for each teacher
|
||||
teacher.setPoints(0); // Replace with actual calculation
|
||||
}
|
||||
}
|
||||
|
||||
// Sort teachers by their points
|
||||
private static void sortTeachers() {
|
||||
Arrays.sort(teachers, (t1, t2) -> Integer.compare(t2.getPoints(), t1.getPoints()));
|
||||
}
|
||||
|
||||
// Print the teachers and their points
|
||||
private static void printTeachers() {
|
||||
System.out.println("Teachers and their points:");
|
||||
|
||||
int rank = 1; // Start with rank 1
|
||||
int previousPoints = -1; // Track the points of the previous teacher
|
||||
int currentRankCount = 0; // Count how many teachers share the same rank
|
||||
|
||||
for (Teacher teacher : teachers) {
|
||||
if (teacher.getPoints() != previousPoints) {
|
||||
rank += currentRankCount; // Update rank if points are different
|
||||
currentRankCount = 1; // Reset count for the new points
|
||||
} else {
|
||||
currentRankCount++; // Increment count for same points
|
||||
}
|
||||
|
||||
// Print the teacher with their rank and points
|
||||
System.out.printf("%d. %s - %d points%n", rank, teacher.getName(), teacher.getPoints());
|
||||
previousPoints = teacher.getPoints(); // Update previous points
|
||||
}
|
||||
}
|
||||
|
||||
// Get user input from the console
|
||||
private static int getUserInput(String textOutput) {
|
||||
System.out.println(textOutput);
|
||||
while (!scanner.hasNextInt()) {
|
||||
System.out.println("Invalid input. Please enter a number.");
|
||||
scanner.next(); // Clear the invalid input
|
||||
}
|
||||
return scanner.nextInt(); // Read user input
|
||||
}
|
||||
|
||||
// Print explanation of point calculations
|
||||
private static void printExplanation() {
|
||||
System.out.println("Point calculation explanation:");
|
||||
System.out.println("1. 5 points for keeping the window open during a small break.");
|
||||
System.out.println("2. Up to 10 points for long breaks, with deductions for window usage.");
|
||||
System.out.println("3. Bonus points for switching teachers.");
|
||||
}
|
||||
|
||||
// Print shutdown animation
|
||||
private static void printShutDown() {
|
||||
System.out.println("Shutting down...");
|
||||
for (int i = 3; i > 0; i--) {
|
||||
System.out.print(i + "...");
|
||||
try {
|
||||
Thread.sleep(1000); // Sleep for 1 second
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
System.out.println("Goodbye!");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
fillInTimeTable();
|
||||
initializeTeachers();
|
||||
calculatePoints();
|
||||
sortTeachers();
|
||||
printTeachers();
|
||||
|
||||
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();
|
||||
printShutDown();
|
||||
} else if (userInput == 0) {
|
||||
printShutDown();
|
||||
} else {
|
||||
// Handle invalid input
|
||||
System.out.println("Invalid input. Please enter 1 for Yes or 0 for No.");
|
||||
}
|
||||
|
||||
scanner.close(); // Close the scanner to avoid resource leaks
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,28 +1,70 @@
|
|||
public class FillTable {
|
||||
// Fill Room 37 timetable
|
||||
static void fillRoom37TimeTable() {
|
||||
// Monday
|
||||
// Tuesday
|
||||
// Wednesday
|
||||
// Thursday
|
||||
// Friday
|
||||
// Define start and end times as class variables
|
||||
// #region Class Variables
|
||||
private static final String[] START_TIMES = {
|
||||
"7:45", "8:35", "9:40", "10:30", "11:20", "12:10", "12:50",
|
||||
"13:35", "14:25", "15:15", "16:15", "17:05"
|
||||
};
|
||||
|
||||
private static final String[] END_TIMES = {
|
||||
"8:30", "9:20", "10:25", "11:15", "12:05", "12:50", "13:30",
|
||||
"14:20", "15:10", "16:10", "17:00", "17:50"
|
||||
};
|
||||
|
||||
// #region fillTable
|
||||
// Example method to fill a timetable with teachers
|
||||
private static void fillTable(String[] teacherNames, String day, String[] startTime, String[] endTime,
|
||||
int roomIndex) {
|
||||
int dayIndex = getDayIndex(day);
|
||||
for (int i = 0; i < teacherNames.length; i++) {
|
||||
// Room is determined by the caller method
|
||||
App.timeTable[roomIndex][dayIndex][i] = new Lesson(37, teacherNames[i], startTime[i], endTime[i], day);
|
||||
}
|
||||
}
|
||||
|
||||
private static int getDayIndex(String day) {
|
||||
switch (day) {
|
||||
case "Monday":
|
||||
return 0;
|
||||
case "Tuesday":
|
||||
return 1;
|
||||
case "Wednesday":
|
||||
return 2;
|
||||
case "Thursday":
|
||||
return 3;
|
||||
case "Friday":
|
||||
return 4;
|
||||
default:
|
||||
return -1; // Invalid day
|
||||
}
|
||||
}
|
||||
|
||||
// Fill 37 timetable
|
||||
// #region table 37
|
||||
static void fill37TimeTable() {
|
||||
int roomIndex = 0;
|
||||
fillTable(new String[] { "Hm", "Py", "Hi", "Hm", "Le", "", "Gi", "Gi", "D", "Ts", "Ts", "" },
|
||||
"Monday", START_TIMES, END_TIMES, roomIndex);
|
||||
}
|
||||
|
||||
// Fill Room 38 timetable
|
||||
static void fillRoom38TimeTable() {
|
||||
// Monday
|
||||
// Tuesday
|
||||
// Wednesday
|
||||
// Thursday
|
||||
// Friday
|
||||
// #region table 38
|
||||
static void fill38TimeTable() {
|
||||
int roomIndex = 1;
|
||||
fillTable(new String[] { "Bz", "Bz", "Bz", "Bz", "Bz", "", "Hn", "Hn", "Bu", "Bu", "Hn", "Hn" },
|
||||
"Monday", START_TIMES, END_TIMES, roomIndex);
|
||||
fillTable(new String[] { "Br", "Kg", "Kh", "Re", "Es", "", "Bt", "EW", "FR", "FR", "VW", "VW" },
|
||||
"Tuesday", START_TIMES, END_TIMES, roomIndex);
|
||||
}
|
||||
|
||||
// Fill Room 39 timetable
|
||||
static void fillRoom39TimeTable() {
|
||||
// Monday
|
||||
// Tuesday
|
||||
// Wednesday
|
||||
// Thursday
|
||||
// Friday
|
||||
// #region table 39
|
||||
static void fill39TimeTable() {
|
||||
int roomIndex = 2;
|
||||
fillTable(new String[] { "", "", "", "", "", "", "", "", "", "", "", "" },
|
||||
"Monday", START_TIMES, END_TIMES, roomIndex);
|
||||
fillTable(new String[] { "", "", "", "", "", "", "", "", "", "", "", "" },
|
||||
"Tuesday", START_TIMES, END_TIMES, roomIndex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +1,36 @@
|
|||
public class Lesson {
|
||||
int room;
|
||||
String teacherName;
|
||||
String startTime;
|
||||
String endTime;
|
||||
String day;
|
||||
private int room;
|
||||
private String teacherName;
|
||||
private String startTime;
|
||||
private String endTime;
|
||||
private String day;
|
||||
|
||||
public Lesson(int room, String teacherName) {
|
||||
// Constructor to initialize all fields
|
||||
public Lesson(int room, String teacherName, String startTime, String endTime, String day) {
|
||||
this.room = room;
|
||||
this.teacherName = teacherName;
|
||||
this.startTime = startTime;
|
||||
this.endTime = endTime;
|
||||
this.day = day;
|
||||
}
|
||||
|
||||
public int getRoom() {
|
||||
return room;
|
||||
}
|
||||
|
||||
public String getTeacherName() {
|
||||
return teacherName;
|
||||
}
|
||||
|
||||
public String getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public String getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
public String getDay() {
|
||||
return day;
|
||||
}
|
||||
}
|
|
@ -1,9 +1,44 @@
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Teacher {
|
||||
private String name;
|
||||
private int points;
|
||||
|
||||
// Mapping of initials to full names
|
||||
private static final Map<String, String> nameMap = new HashMap<>();
|
||||
|
||||
// Static block to initialize the name mappings
|
||||
static {
|
||||
nameMap.put("Hm", "Hummel");
|
||||
nameMap.put("Bä", "Bäcker");
|
||||
nameMap.put("Bd", "Bender");
|
||||
nameMap.put("Bu", "Burger");
|
||||
nameMap.put("Cg", "Chung");
|
||||
nameMap.put("Di", "Dimitrov");
|
||||
nameMap.put("Do", "Doe");
|
||||
nameMap.put("Eh", "Ehrlich");
|
||||
nameMap.put("Es", "Esposito");
|
||||
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");
|
||||
// Add more mappings as needed
|
||||
}
|
||||
|
||||
// Constructor
|
||||
public Teacher(String name) {
|
||||
this.name = name;
|
||||
setName(name);
|
||||
points = 0;
|
||||
}
|
||||
|
||||
|
@ -12,7 +47,7 @@ public class Teacher {
|
|||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
this.name = nameMap.getOrDefault(name, name); // Set the name based on the mapping
|
||||
}
|
||||
|
||||
public int getPoints() {
|
||||
|
|
Loading…
Reference in a new issue