diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index 435139b..32e57ac 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -1,17 +1,82 @@ package org.codedifferently; -//TIP To Run code, press or -// click the icon in the gutter. +import java.util.ArrayList; +import java.util.Scanner; + public class Main { public static void main(String[] args) { - //TIP Press with your caret at the highlighted text - // to see how IntelliJ IDEA suggests fixing it. - System.out.printf("Hello and welcome!"); - - for (int i = 1; i <= 5; i++) { - //TIP Press to start debugging your code. We have set one breakpoint - // for you, but you can always add more by pressing . - System.out.println("i = " + i); + + // Initialize office and technicians + ArrayList techs = new ArrayList<>(); + techs.add(new Technician("ELECTRICAL", "Wilson Fisk")); + techs.add(new Technician("PLUMBING", "Steve Rogers")); + techs.add(new Technician("HVAC", "Frank Castle")); + techs.add(new Technician("APPLIANCE", "Luke Cage")); + + ArrayList requests = new ArrayList<>(); + MaintenanceOffice office = new MaintenanceOffice(techs, requests); + + // Level 1: create at least 3 requests + MaintenanceRequest r1 = new MaintenanceRequest("Alice", 101, "ELECTRICAL", 3); + MaintenanceRequest r2 = new MaintenanceRequest("Bob", 202, "PLUMBING", 2); + MaintenanceRequest r3 = new MaintenanceRequest("Charlie", 303, "HVAC", 4); + + office.addRequest(r1); + office.addRequest(r2); + office.assignTechnician(r2); + //mark a request as done + r2.setStatus("DONE"); + office.addRequest(r3); + office.assignTechnician(r3); + + System.out.println("*** Initial Requests ***"); + for (MaintenanceRequest request : office.getRequests()) { + System.out.println(request.toString()); + if (request.getSeverity() >= 4) { + System.out.println("HIGH PRIORITY"); + } + } + System.out.println(); + System.out.println("************************************"); + + // level 2 and 3: intake from user and assign and update + Scanner scanner = new Scanner(System.in); + while (true) { + System.out.println("Enter tenant name (or 'done' to finish):"); + String tenantName = scanner.nextLine(); + if (tenantName.equalsIgnoreCase("done")) { + break; + } + + System.out.println("Enter apartment number:"); + String aptNum = scanner.nextLine().toUpperCase(); + + System.out.println("Enter issue type (Electrical, Plumbing, HVAC, Appliance):"); + String issueType = scanner.nextLine().toUpperCase(); + + System.out.println("Enter severity (1-5):"); + int severity; + try { + severity = Integer.parseInt(scanner.nextLine()); + if (severity < 1 || severity > 5) { + System.out.println("Invalid severity. Must be 1-5. Defaulting to 3."); + severity = 3; + } + } catch (NumberFormatException e) { + System.out.println("Invalid number. Defaulting to 3."); + severity = 3; + } + + MaintenanceRequest newRequest = new MaintenanceRequest(tenantName, Integer.parseInt(aptNum), issueType, severity); + office.addRequest(newRequest); + // Print confirmation + office.assignTechnician(newRequest); + System.out.println("Request added: " + newRequest); } + + //level 4: daily report + office.generateDailyReport(); + + scanner.close(); } } \ No newline at end of file diff --git a/src/main/java/org/codedifferently/MaintenanceOffice.java b/src/main/java/org/codedifferently/MaintenanceOffice.java new file mode 100644 index 0000000..60aa21e --- /dev/null +++ b/src/main/java/org/codedifferently/MaintenanceOffice.java @@ -0,0 +1,162 @@ +package org.codedifferently; +import java.util.ArrayList; + +public class MaintenanceOffice { + //private fields for the maintenance office + private ArrayList technicians; + private ArrayList requests; + + //constructor + public MaintenanceOffice(ArrayList technicians, ArrayList requests) { + this.technicians = technicians; + this.requests = requests; + } + + //getters and setters to access private instance variables + public ArrayList getTechnicians() { + return technicians; + } + + public ArrayList getRequests() { + return requests; + } + + //adds a request to the request lists + public void addRequest(MaintenanceRequest request){ + requests.add(request); + } + + //adds a tech to the list of technicians + public void addTechnician(Technician technician){ + technicians.add(technician); + } + + //assigns a technician to the request that's being passed in + public void assignTechnician(MaintenanceRequest request){ + //electrical high severity warning + if (request.getIssueType().equals("ELECTRICAL") + && request.getSeverity() >= 4) { + + System.out.println("WARNING: High severity electrical issue!"); + } + + // immediate dispatch for severity 5 + if (request.getSeverity() == 5) { + System.out.println("DISPATCH IMMEDIATELY!"); + } + + for (Technician technician : technicians){ + if(technician.getType().equals(request.getIssueType())) { + request.setAssignedTechnician(technician); + updateRequestStatus(request,"IN_PROGRESS"); + return; + } + } + System.out.println("No technician available for this issue."); + } + + //updates the request status of the request passed in + public void updateRequestStatus(MaintenanceRequest request, String newStatus) { + request.setStatus(newStatus); + } + + //closes the request + public void closeRequest(MaintenanceRequest request){ + System.out.println("Request closed successfully."); + } + + //displays detailed info about the requests that come in + public void generateDailyReport() { + int open = countOpenRequests(); + int closed = countClosedRequests(); + int[] severityCounts = countSeverity(); // [low, medium, high] + int low = severityCounts[0]; + int medium = severityCounts[1]; + int high = severityCounts[2]; + + String mostCommonIssueType = getMostCommonIssueType(); + int highPriorityCount = high; // high severity = severity 4-5 + + // Print report + System.out.println("***** DAILY MAINTENANCE REPORT *****"); + System.out.println("Total Requests: " + requests.size()); + System.out.println("Open Requests: " + open); + System.out.println("Closed Requests: " + closed); + + System.out.println("Severity Breakdown:"); + System.out.println("Low (1-2): " + low); + System.out.println("Medium (3): " + medium); + System.out.println("High (4-5): " + high); + + System.out.println("Most Common Issue Type: " + mostCommonIssueType); + + if (highPriorityCount > 3) { + System.out.println("OVERLOAD WARNING: Too many high priority requests!"); + } + } + +// helper methods for the daily report method + //gets the total amount of the open requests + private int countOpenRequests() { + int count = 0; + for (MaintenanceRequest request : requests) { + if (!request.getStatus().equals("DONE")) { + count++; + } + } + return count; + } + + //gets the total amount of closed requests + private int countClosedRequests() { + int count = 0; + for (MaintenanceRequest r : requests) { + if (r.getStatus().equals("DONE")) { + count++; + } + } + return count; + } + + private int[] countSeverity() { + int low = 0, medium = 0, high = 0; + for (MaintenanceRequest request : requests) { + if (request.getSeverity()<= 2) { + low++; + } else if (request.getSeverity() == 3) { + medium++; + } else { + high++; + } + } + return new int[]{low, medium, high}; + } + + //gets the type that appears the most in the list of the requests + private String getMostCommonIssueType() { + String mostCommonType = ""; + int highestCount = 0; + ArrayList checked = new ArrayList<>(); + + for (MaintenanceRequest request : requests) { + String type = request.getIssueType(); + + // only count this issue type if we haven’t already processed it + if (!checked.contains(type)) { + int count = 0; + for (MaintenanceRequest r : requests) { + if (r.getIssueType().equals(type)) { + count++; + } + } + //max pattern + if (count > highestCount) { + highestCount = count; + mostCommonType = type; + } + checked.add(type); + } + } + return mostCommonType; + } +} diff --git a/src/main/java/org/codedifferently/MaintenanceRequest.java b/src/main/java/org/codedifferently/MaintenanceRequest.java new file mode 100644 index 0000000..6b3eb26 --- /dev/null +++ b/src/main/java/org/codedifferently/MaintenanceRequest.java @@ -0,0 +1,86 @@ +package org.codedifferently; + +public class MaintenanceRequest { + //fields of a maintenance request + private String tenantName; + private int apartmentNumber; + private String issueType; + private int severity; + private String status; + private Technician assignedTechnician; + + //constructor + public MaintenanceRequest(String tenantName, int apartmentNumber, String issueType, int severity) { + this.tenantName = tenantName; + this.apartmentNumber = apartmentNumber; + this.issueType = issueType; + this.severity = severity; + this.status = "NEW"; + } + + //getters and setters to access private instance variables + public String getTenantName() { + return tenantName; + } + + public void setTenantName(String tenantName) { + this.tenantName = tenantName; + } + + public int getApartmentNumber() { + return apartmentNumber; + } + + public void setApartmentNumber(int 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) { + //checks to see if the severity is valid or not + if (severity >= 1 && severity <= 5) { + this.severity = severity; + } else { + System.out.println("Invalid severity."); + } + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public Technician getAssignedTechnician() { + return assignedTechnician; + } + + public void setAssignedTechnician(Technician assignedTechnician) { + this.assignedTechnician = assignedTechnician; + } + + //displays the info of the request + @Override + public String toString() { + String techName = (assignedTechnician != null) ? assignedTechnician.getName() : "None"; + return "Tenant: " + tenantName + + " | Apt: " + apartmentNumber + + " | Issue: " + issueType + + " | Severity: " + severity + + " | Status: " + status + + " | Assigned Technician: " + techName; + } +} diff --git a/src/main/java/org/codedifferently/Technician.java b/src/main/java/org/codedifferently/Technician.java new file mode 100644 index 0000000..da7a893 --- /dev/null +++ b/src/main/java/org/codedifferently/Technician.java @@ -0,0 +1,30 @@ +package org.codedifferently; + +public class Technician { + //private fields of a technician + private String type; + private String name; + + //constructor + public Technician(String type, String name){ + this.type = type; + this.name = name; + } + + //getters and setters for the private fields + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +}