diff --git a/src/main/java/maintenance/Main.java b/src/main/java/maintenance/Main.java new file mode 100644 index 0000000..1a23303 --- /dev/null +++ b/src/main/java/maintenance/Main.java @@ -0,0 +1,126 @@ +package maintenance; + +import java.util.Scanner; + +public class Main { + + public static void main(String[] args) { + + MaintenanceOffice office = new MaintenanceOffice(); + + + MaintenanceRequest r1 = new MaintenanceRequest("Alex", "12A", "Plumbing", 3); + + MaintenanceRequest r2 = new MaintenanceRequest("Bri", "7C", "Electrical", 4); + + MaintenanceRequest r3 = new MaintenanceRequest("Chris", "4B", "HVAC", 5); + + office.addRequest(r1); + + office.addRequest(r2); + + office.addRequest(r3); + + System.out.println("=== LEVEL 1: INITIAL REQUESTS ==="); + + for (MaintenanceRequest r : office.getRequests()) { + + System.out.println(r); + + if (r.getSeverity() >= 4) { + + System.out.println("HIGH PRIORITY"); + } + } + + + Scanner scanner = new Scanner(System.in); + + System.out.println("\n=== LEVEL 2: ENTER NEW REQUESTS (type 'done' for tenant name to stop) ==="); + + while (true) { + + System.out.print("\nTenant name: "); + + String tenant = scanner.nextLine().trim(); + + if (tenant.equalsIgnoreCase("done")) break; + + System.out.print("Apartment number: "); + + String apt = scanner.nextLine().trim(); + + System.out.print("Issue type (Plumbing/Electrical/HVAC/etc): "); + + String issue = scanner.nextLine().trim(); + + int severity = readSeverity(scanner); + + MaintenanceRequest newReq = new MaintenanceRequest(tenant, apt, issue, severity); + + office.addRequest(newReq); + + System.out.println("✅ Request logged: " + newReq); + + + if (issue.equalsIgnoreCase("Electrical") && severity >= 4) { + + System.out.println("⚠ WARNING: High severity electrical issue!"); + } + if (severity == 5) { + + System.out.println("🚨 DISPATCH IMMEDIATELY: Severity 5!"); + } + } + + + if (!office.getRequests().isEmpty()) { + + MaintenanceRequest first = office.getRequests().get(0); + + office.updateStatus(first, "IN_PROGRESS"); + + office.updateStatus(first, "DONE"); + office.closeRequest(first); + } + + + office.printDailyReport(); + + + System.out.println("=== FINAL REQUEST LIST ==="); + + for (MaintenanceRequest r : office.getRequests()) { + + System.out.println(r); + } + + scanner.close(); + } + + private static int readSeverity(Scanner scanner) { + while (true) { + + System.out.print("Severity (1-5): "); + + String input = scanner.nextLine().trim(); + + try { + + int sev = Integer.parseInt(input); + + if (sev < 1 || sev > 5) { + + System.out.println("Enter a number from 1 to 5."); + + continue; + } + return sev; + + } catch (NumberFormatException e) { + + System.out.println("Enter a valid integer from 1 to 5."); + } + } + } +} \ No newline at end of file diff --git a/src/main/java/maintenance/MaintenanceOffice.java b/src/main/java/maintenance/MaintenanceOffice.java new file mode 100644 index 0000000..0ed4c69 --- /dev/null +++ b/src/main/java/maintenance/MaintenanceOffice.java @@ -0,0 +1,158 @@ +package maintenance; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +public class MaintenanceOffice { + + private final ArrayList requests; + + public MaintenanceOffice() { + + this.requests = new ArrayList<>(); + } + + public void addRequest(MaintenanceRequest request) { + + assignTech(request); + + requests.add(request); + } + + public ArrayList getRequests() { + + return requests; + } + + + public void assignTech(MaintenanceRequest request) { + + int sev = request.getSeverity(); + + if (sev <= 2) { + + request.setAssignedTech("Tech A (General)"); + + } else if (sev <= 4) { + + request.setAssignedTech("Tech B (Senior)"); + + } else { + + request.setAssignedTech("Tech C (Emergency)"); + } + } + + + public boolean updateStatus(MaintenanceRequest request, String newStatus) { + + if (!isValidStatus(newStatus)) { + + System.out.println("Invalid status. Allowed: NEW, IN_PROGRESS, DONE"); + + return false; + } + request.setStatus(newStatus); + return true; + } + + public boolean closeRequest(MaintenanceRequest request) { + + if (!"DONE".equalsIgnoreCase(request.getStatus())) { + + System.out.println("Cannot close unless status is DONE."); + + return false; + } + + request.setStatus("CLOSED"); + + return true; + } + + private boolean isValidStatus(String status) { + + if (status == null) return false; + + String s = status.trim().toUpperCase(); + + return s.equals("NEW") || s.equals("IN_PROGRESS") || s.equals("DONE"); + } + + + public void printDailyReport() { + + int total = requests.size(); + + int open = 0; + + int closed = 0; + + int low = 0; + + int medium = 0; + + int high = 0; + + Map issueCounts = new HashMap<>(); + + int highPriorityCount = 0; + + for (MaintenanceRequest r : requests) { + + String status = r.getStatus() == null ? "" : r.getStatus().toUpperCase(); + + + if (status.equals("CLOSED")) closed++; + + else open++; + + int sev = r.getSeverity(); + + if (sev <= 2) low++; + + else if (sev == 3) medium++; + + else high++; + + if (sev >= 4) highPriorityCount++; + + String issue = r.getIssueType() == null ? "UNKNOWN" : r.getIssueType().trim(); + + issueCounts.put(issue, issueCounts.getOrDefault(issue, 0) + 1); + } + + String mostCommonIssue = "NONE"; + + int maxCount = 0; + + for (String issue : issueCounts.keySet()) { + + int count = issueCounts.get(issue); + + if (count > maxCount) { + + maxCount = count; + + mostCommonIssue = issue; + } + } + + System.out.println("\n=== DAILY MAINTENANCE REPORT ==="); + + System.out.println("Total requests: " + total); + + System.out.println("Open: " + open + " | Closed: " + closed); + + System.out.println("Severity counts -> Low(1-2): " + low + " | Medium(3): " + medium + " | High(4-5): " + high); + + System.out.println("Most common issue type: " + mostCommonIssue + " (" + maxCount + ")"); + + if (highPriorityCount > 3) { + + System.out.println("⚠ OVERLOAD WARNING: High priority requests exceed 3!"); + } + System.out.println("================================\n"); + } +} \ No newline at end of file diff --git a/src/main/java/maintenance/MaintenanceRequest.java b/src/main/java/maintenance/MaintenanceRequest.java new file mode 100644 index 0000000..94ea3be --- /dev/null +++ b/src/main/java/maintenance/MaintenanceRequest.java @@ -0,0 +1,122 @@ +package maintenance; + +public class MaintenanceRequest { + + private String tenantName; + + private String apartmentNumber; + + private String issueType; + + private int severity; + + private String status; + + private String assignedTech; // assigned at Level 3 + + + public MaintenanceRequest() { + + this.status = "NEW"; + + this.assignedTech = "UNASSIGNED"; + } + + + public MaintenanceRequest(String tenantName, String apartmentNumber, String issueType, int severity) { + + this.tenantName = tenantName; + + this.apartmentNumber = apartmentNumber; + + this.issueType = issueType; + + setSeverity(severity); + + this.status = "NEW"; + + this.assignedTech = "UNASSIGNED"; + } + + public String getTenantName() { + + return tenantName; + } + + public void setTenantName(String tenantName) { + + this.tenantName = tenantName; + } + + public String getApartmentNumber() { + + return apartmentNumber; + } + + public void setApartmentNumber(String apartmentNumber) { + + this.apartmentNumber = apartmentNumber; + } + + public String getIssueType() { + + return issueType; + } + + public void setIssueType(String issueType) { + + this.issueType = issueType; + } + + public int getSeverity() { + + return severity; + } + + public void setSeverity(int severity) { + + if (severity < 1) severity = 1; + + if (severity > 5) severity = 5; + + this.severity = severity; + } + + public String getStatus() { + + return status; + } + + public void setStatus(String status) { + + this.status = status; + } + + public String getAssignedTech() { + + return assignedTech; + } + + public void setAssignedTech(String assignedTech) { + + this.assignedTech = assignedTech; + } + + public boolean isHighPriority() { + + return severity >= 4; + } + + @Override + public String toString() { + + return "Request{" + + "tenant='" + tenantName + '\'' + + ", apt='" + apartmentNumber + '\'' + + ", issue='" + issueType + '\'' + + ", severity=" + severity + + ", status='" + status + '\'' + + ", tech='" + assignedTech + '\'' + + '}'; + } +} \ No newline at end of file