diff --git a/src/main/java/org/codedifferently/maxxblue/maintenance/Main.java b/src/main/java/org/codedifferently/maxxblue/maintenance/Main.java new file mode 100644 index 0000000..30e735d --- /dev/null +++ b/src/main/java/org/codedifferently/maxxblue/maintenance/Main.java @@ -0,0 +1,135 @@ +package org.codedifferently.maxxblue.maintenance; +import java.util.Scanner; + +public class Main { + + public static void main(String[] args) { + + // Create office system + MaintenanceOffice office = new MaintenanceOffice(); + + // Scanner for user input + Scanner scanner = new Scanner(System.in); + + boolean running = true; + + // Main menu loop + while (running) { + + System.out.println("\n===== APARTMENT MAINTENANCE SYSTEM ====="); + System.out.println("1. Add Maintenance Request"); + System.out.println("2. Print Daily Report"); + System.out.println("3. Close Request (Maintenance Only)"); + System.out.println("4. Exit"); + System.out.print("Choose an option: "); + + String choice = scanner.nextLine(); + + switch (choice) { + + case "1": + addRequest(scanner, office); + break; + + case "2": + office.printDailyReport(); + break; + + case "3": + closeRequestMenu(scanner, office); + break; + + case "4": + running = false; + System.out.println("Exiting system..."); + break; + + default: + System.out.println("Invalid option. Try again."); + } + } + + scanner.close(); + } + + // =============================== + // ADD REQUEST METHOD + // =============================== + private static void addRequest(Scanner scanner, MaintenanceOffice office) { + + System.out.print("Tenant Name: "); + String name = scanner.nextLine(); + + System.out.print("Apartment Number: "); + String apt = scanner.nextLine(); + + System.out.print("Issue Type: "); + String issue = scanner.nextLine(); + + System.out.print("Severity (1-5): "); + int severity = readInt(scanner); + + // Create request object + MaintenanceRequest request = + new MaintenanceRequest(name, apt, issue, severity); + + // Electrical + high severity warning + if (issue.equalsIgnoreCase("Electrical") && severity >= 4) { + System.out.println("⚠ WARNING: High severity electrical issue!"); + } + + // Immediate dispatch rule + if (severity == 5) { + System.out.println("🚨 DISPATCH IMMEDIATELY!"); + } + + // Add request to office system + office.addRequest(request); + + System.out.println("Assigned Tech: " + request.getAssignedTech()); + + // USER can only set NEW or IN_PROGRESS + System.out.print("Update Status (NEW/IN_PROGRESS): "); + String status = scanner.nextLine(); + + office.updateStatus(request, status); + + System.out.println("Request Saved Successfully!"); + } + + // =============================== + // MAINTENANCE CLOSE METHOD + // =============================== + private static void closeRequestMenu(Scanner scanner, MaintenanceOffice office) { + + System.out.print("Enter tenant name to close request: "); + String name = scanner.nextLine(); + + // Search for matching request + for (MaintenanceRequest r : office.getRequests()) { + + if (r.getTenantName().equalsIgnoreCase(name)) { + + // Maintenance attempts to close it + office.closeRequest(r); + return; + } + } + + System.out.println("Request not found."); + } + + // =============================== + // SAFE INTEGER INPUT METHOD + // =============================== + private static int readInt(Scanner scanner) { + + while (true) { + try { + return Integer.parseInt(scanner.nextLine()); + } catch (NumberFormatException e) { + System.out.print("Enter a valid number: "); + } + } + } +} \ No newline at end of file diff --git a/src/main/java/org/codedifferently/maxxblue/maintenance/MaintenanceOffice.java b/src/main/java/org/codedifferently/maxxblue/maintenance/MaintenanceOffice.java new file mode 100644 index 0000000..4ccc7ba --- /dev/null +++ b/src/main/java/org/codedifferently/maxxblue/maintenance/MaintenanceOffice.java @@ -0,0 +1,154 @@ +package org.codedifferently.maxxblue.maintenance; + +import java.util.ArrayList; +import java.util.HashMap; + +// Import Map interface +import java.util.Map; + +// Defines MaintenanceOffice class +public class MaintenanceOffice { + + // List to store all maintenance requests + private final ArrayList requests = new ArrayList<>(); + + // Adds a request to the system + public void addRequest(MaintenanceRequest request) { + + // Assign tech before storing + assignTech(request); + + // Add request to list + requests.add(request); + } + + // Assign tech based on severity + public void assignTech(MaintenanceRequest request) { + + // Get severity level + int s = request.getSeverity(); + + // If highest severity + if (s == 5) { + request.setAssignedTech("EMERGENCY TEAM"); + + // High priority + } else if (s >= 4) { + request.setAssignedTech("Senior Tech"); + + // Medium + } else if (s == 3) { + request.setAssignedTech("General Tech"); + + // Low + } else { + request.setAssignedTech("Apprentice Tech"); + } + } + + // Update status with validation + public boolean updateStatus(MaintenanceRequest request, String newStatus) { + + // Prevent null input + if (newStatus == null) return false; + + // Normalize text (remove spaces, make uppercase) + String normalized = newStatus.trim().toUpperCase(); + + // Only allow specific statuses + if (!normalized.equals("NEW") && + !normalized.equals("IN_PROGRESS") && + !normalized.equals("DONE")) { + + System.out.println("Invalid status."); + return false; + } + + // Update status + request.setStatus(normalized); + return true; + } + + // Only allow closing if DONE + public boolean closeRequest(MaintenanceRequest request) { + + // If not DONE, reject closing + if (!"DONE".equalsIgnoreCase(request.getStatus())) { + System.out.println("Cannot close unless DONE."); + return false; + } + + // Otherwise, allow close + return true; + } + + // Return all requests + public ArrayList getRequests() { + return requests; + } + + // Print daily report + public void printDailyReport() { + + // Count totals + int total = requests.size(); + int open = 0; + int closed = 0; + + int low = 0; + int medium = 0; + int high = 0; + + Map issueCounts = new HashMap<>(); + int highPriorityOpen = 0; + + // Loop through all requests + for (MaintenanceRequest r : requests) { + + // Count open/closed + if ("DONE".equalsIgnoreCase(r.getStatus())) { + closed++; + } else { + open++; + } + + // Count severity categories + if (r.getSeverity() <= 2) low++; + else if (r.getSeverity() == 3) medium++; + else high++; + + // Count issue types + String issue = r.getIssueType(); + issueCounts.put(issue, issueCounts.getOrDefault(issue, 0) + 1); + + // Count open high priority + if (r.getSeverity() >= 4 && !"DONE".equalsIgnoreCase(r.getStatus())) { + highPriorityOpen++; + } + } + + // Find most common issue + String mostCommon = "N/A"; + int max = 0; + + for (Map.Entry entry : issueCounts.entrySet()) { + if (entry.getValue() > max) { + max = entry.getValue(); + mostCommon = entry.getKey(); + } + } + + // Print report + System.out.println("\n=== DAILY REPORT ==="); + System.out.println("Total: " + total); + System.out.println("Open: " + open); + System.out.println("Closed: " + closed); + System.out.println("Low: " + low + " Medium: " + medium + " High: " + high); + System.out.println("Most Common Issue: " + mostCommon); + + // Overload warning + if (highPriorityOpen > 3) { + System.out.println("OVERLOAD WARNING!"); + } + } +} \ No newline at end of file diff --git a/src/main/java/org/codedifferently/maxxblue/maintenance/MaintenanceRequest.java b/src/main/java/org/codedifferently/maxxblue/maintenance/MaintenanceRequest.java new file mode 100644 index 0000000..06a97a0 --- /dev/null +++ b/src/main/java/org/codedifferently/maxxblue/maintenance/MaintenanceRequest.java @@ -0,0 +1,139 @@ +package org.codedifferently.maxxblue.maintenance; + + +public class MaintenanceRequest { + + // Stores the tenant's name + private String tenantName; + + // Stores the apartment number + private String apartmentNumber; + + // Stores the type of issue (Plumbing, Electrical, etc.) + private String issueType; + + // Stores severity level from 1–5 + private int severity; + + // Stores request status (NEW, IN_PROGRESS, DONE) + private String status; + + // Stores the assigned technician + private String assignedTech; + + // Default constructor (no parameters) + public MaintenanceRequest() { + // Default status is NEW + this.status = "NEW"; + + // Default tech is UNASSIGNED + this.assignedTech = "UNASSIGNED"; + } + + // Parameterized constructor (sets all main values) + public MaintenanceRequest(String tenantName, String apartmentNumber, String issueType, int severity) { + + // Assign tenant name + this.tenantName = tenantName; + + // Assign apartment number + this.apartmentNumber = apartmentNumber; + + // Assign issue type + this.issueType = issueType; + + // Call setter to validate severity + setSeverity(severity); + + // Default status is NEW + this.status = "NEW"; + + // Default tech is UNASSIGNED + this.assignedTech = "UNASSIGNED"; + } + + // Getter for tenantName + public String getTenantName() { + return tenantName; + } + + // Setter for tenantName + public void setTenantName(String tenantName) { + this.tenantName = tenantName; + } + + // Getter for apartmentNumber + public String getApartmentNumber() { + return apartmentNumber; + } + + // Setter for apartmentNumber + public void setApartmentNumber(String apartmentNumber) { + this.apartmentNumber = apartmentNumber; + } + + // Getter for issueType + public String getIssueType() { + return issueType; + } + + // Setter for issueType + public void setIssueType(String issueType) { + this.issueType = issueType; + } + + // Getter for severity + public int getSeverity() { + return severity; + } + + // Setter with validation (keeps severity between 1 and 5) + public void setSeverity(int severity) { + + // If less than 1, force to 1 + if (severity < 1) { + this.severity = 1; + + // If greater than 5, force to 5 + } else if (severity > 5) { + this.severity = 5; + + // Otherwise assign normally + } else { + this.severity = severity; + } + } + + // Getter for status + public String getStatus() { + return status; + } + + // Setter for status + public void setStatus(String status) { + this.status = status; + } + + // Getter for assignedTech + public String getAssignedTech() { + return assignedTech; + } + + // Setter for assignedTech + public void setAssignedTech(String assignedTech) { + this.assignedTech = assignedTech; + } + + // toString method to print request details + @Override + public String toString() { + return "Request{" + + "tenant='" + tenantName + '\'' + + ", apt='" + apartmentNumber + '\'' + + ", issueType='" + issueType + '\'' + + ", severity=" + severity + + ", status='" + status + '\'' + + ", tech='" + assignedTech + '\'' + + '}'; + } +}