Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 135 additions & 0 deletions src/main/java/org/codedifferently/maxxblue/maintenance/Main.java
Original file line number Diff line number Diff line change
@@ -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: ");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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<MaintenanceRequest> 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<MaintenanceRequest> 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<String, Integer> 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<String, Integer> 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!");
}
}
}
Loading