From cadeadd89030f91d2f9d62305351856b16dd8f2a Mon Sep 17 00:00:00 2001 From: Omnicscient <115184891+Omnicscient@users.noreply.github.com> Date: Tue, 16 Dec 2025 23:30:43 +0300 Subject: [PATCH] Task 2.4 Step 2: Display utilization percentage --- .../ScheduleClassroomController.java | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/example/se302/controller/ScheduleClassroomController.java b/src/main/java/org/example/se302/controller/ScheduleClassroomController.java index d7bcea8..c3bd5fd 100644 --- a/src/main/java/org/example/se302/controller/ScheduleClassroomController.java +++ b/src/main/java/org/example/se302/controller/ScheduleClassroomController.java @@ -85,6 +85,9 @@ public class ScheduleClassroomController { " (Capacity: " + selected.getCapacity() + ")"); ObservableList entries = FXCollections.observableArrayList(); + int totalSlots = 0; + int usedSlots = 0; + int totalStudents = 0; // If we have assignments, filter by this classroom if (currentAssignments != null && !currentAssignments.isEmpty()) { @@ -105,15 +108,38 @@ public class ScheduleClassroomController { // Format time String timeStr = "Slot " + (assignment.getTimeSlotIndex() + 1); + // Calculate utilization percentage for this slot + int studentCount = assignment.getStudentCount(); + int capacity = selected.getCapacity(); + int utilizationPercent = capacity > 0 ? (studentCount * 100) / capacity : 0; + String utilizationStr = utilizationPercent + "%"; + entries.add(new ClassroomSlotEntry( dateStr, timeStr, assignment.getCourseCode(), - assignment.getStudentCount(), "-")); + studentCount, utilizationStr)); + + usedSlots++; + totalStudents += studentCount; } } + + // Calculate total possible slots + if (configuration != null) { + totalSlots = configuration.getNumDays() * configuration.getSlotsPerDay(); + } } scheduleTable.setItems(entries); - utilizationLabel.setText("Exams shown: " + entries.size()); + + // Update overall utilization label + if (totalSlots > 0) { + int overallUtilization = (usedSlots * 100) / totalSlots; + utilizationLabel.setText(String.format( + "Overall Utilization: %d%% (%d/%d slots used, %d total students)", + overallUtilization, usedSlots, totalSlots, totalStudents)); + } else { + utilizationLabel.setText("Overall Utilization: 0% (No schedule data available)"); + } } // Helper class for table entries