diff --git a/src/main/java/org/codedifferently/CleaningRequest.java b/src/main/java/org/codedifferently/CleaningRequest.java new file mode 100644 index 0000000..bd45d02 --- /dev/null +++ b/src/main/java/org/codedifferently/CleaningRequest.java @@ -0,0 +1,58 @@ +package org.codedifferently; + +// CleaningRequest represents cleaning services for an apartment +public class CleaningRequest extends ServiceRequest { + + // Area that needs cleaning + private String cleaningArea; + + // Severity level of cleaning request + private int issueSeverity; + + // Default constructor + public CleaningRequest() { + super(); + } + + // Constructor with parameters + public CleaningRequest(String tenantName, String apartmentNumber, String cleaningArea, int issueSeverity) { + super(tenantName, apartmentNumber); + this.cleaningArea = cleaningArea; + this.issueSeverity = issueSeverity; + } + + // Overrides abstract method + @Override + public String getRequestType() { + return "Cleaning"; + } + + // Getter methods + public String getCleaningArea() { + return cleaningArea; + } + + public int getIssueSeverity() { + return issueSeverity; + } + + // Setter methods + public void setCleaningArea(String cleaningArea) { + this.cleaningArea = cleaningArea; + } + + public void setIssueSeverity(int issueSeverity) { + this.issueSeverity = issueSeverity; + } + + // Convert object into readable string + @Override + public String toString() { + return "Tenant: " + tenantName + + " | Apt: " + apartmentNumber + + " | Type: " + getRequestType() + + " | Area: " + cleaningArea + + " | Severity: " + issueSeverity + + " | Status: " + status; + } +} \ No newline at end of file diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index 435139b..53c0653 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -1,17 +1,282 @@ 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!"); + ArrayList requests = new ArrayList<>(); + ArrayList accounts = new ArrayList<>(); + Scanner scan = new Scanner(System.in); + + boolean running = true; + + while (running) { + System.out.println("\n=== Apartment Service & Payment System ==="); + System.out.println("1. Add Resident Account"); + System.out.println("2. Submit Maintenance Request"); + System.out.println("3. Submit Cleaning Request"); + System.out.println("4. View All Requests"); + System.out.println("5. Update Request Status"); + System.out.println("6. View Resident Accounts"); + System.out.println("7. Make Payment"); + System.out.println("8. Daily Report"); + System.out.println("9. Exit"); + System.out.print("Choose an option: "); + + int choice; + if (scan.hasNextInt()) { + choice = scan.nextInt(); + scan.nextLine(); + } else { + System.out.println("Please enter a number."); + scan.nextLine(); + continue; + } +// + switch (choice) { + case 1: + addResidentAccount(accounts, scan); + break; + case 2: + addMaintenanceRequest(requests, accounts, scan); + break; + case 3: + addCleaningRequest(requests, accounts, scan); + break; + case 4: + viewAllRequests(requests); + break; + case 5: + updateRequestStatus(requests, scan); + break; + case 6: + viewResidentAccounts(accounts); + break; + case 7: + makePayment(accounts, scan); + break; + case 8: + dailyReport(requests, accounts); + break; + case 9: + running = false; + System.out.println("Goodbye."); + break; + default: + System.out.println("Invalid choice."); + } + } + + scan.close(); + } + + public static void addResidentAccount(ArrayList accounts, Scanner scan) { + System.out.print("Enter resident name: "); + String name = scan.nextLine(); + + System.out.print("Enter apartment number: "); + String apartmentNumber = scan.nextLine(); + + System.out.print("Enter starting balance: "); + double balance = readDouble(scan); + + ResidentAccount account = new ResidentAccount(name, apartmentNumber, balance); + accounts.add(account); + + System.out.println("Resident account added."); + } + + public static void addMaintenanceRequest(ArrayList requests, + ArrayList accounts, + Scanner scan) { + System.out.print("Enter tenant name: "); + String tenantName = scan.nextLine(); + + System.out.print("Enter apartment number: "); + String apartmentNumber = scan.nextLine(); + + System.out.print("Enter issue type: "); + String issueType = scan.nextLine(); + + System.out.print("Enter issue severity (1-5): "); + int severity = readInt(scan); + + MaintenanceRequest request = new MaintenanceRequest(tenantName, apartmentNumber, issueType, severity); + requests.add(request); + + ResidentAccount account = findAccount(accounts, apartmentNumber); + if (account != null) { + account.addCharge(15.00); + System.out.println("Maintenance request submitted. $15.00 charge added."); + } else { + System.out.println("Maintenance request submitted. No matching resident account found."); + } + } + + public static void addCleaningRequest(ArrayList requests, + ArrayList accounts, + Scanner scan) { + System.out.print("Enter tenant name: "); + String tenantName = scan.nextLine(); + + System.out.print("Enter apartment number: "); + String apartmentNumber = scan.nextLine(); + + System.out.print("Enter cleaning area: "); + String cleaningArea = scan.nextLine(); + + System.out.print("Enter severity (1-5): "); + int severity = readInt(scan); + + CleaningRequest request = new CleaningRequest(tenantName, apartmentNumber, cleaningArea, severity); + requests.add(request); + + ResidentAccount account = findAccount(accounts, apartmentNumber); + if (account != null) { + account.addCharge(25.00); + System.out.println("Cleaning request submitted. $25.00 charge added."); + } else { + System.out.println("Cleaning request submitted. No matching resident account found."); + } + } + + public static void viewAllRequests(ArrayList requests) { + if (requests.isEmpty()) { + System.out.println("No requests found."); + return; + } + + System.out.println("\n--- ALL REQUESTS ---"); + for (int i = 0; i < requests.size(); i++) { + System.out.println((i + 1) + ". " + requests.get(i)); + } + } + + public static void updateRequestStatus(ArrayList requests, Scanner scan) { + if (requests.isEmpty()) { + System.out.println("No requests to update."); + return; + } + + viewAllRequests(requests); + System.out.print("Choose request number to update: "); + int choice = readInt(scan); + + if (choice < 1 || choice > requests.size()) { + System.out.println("Invalid request number."); + return; + } + + ServiceRequest request = requests.get(choice - 1); + + if (request.getStatus().equals("NEW")) { + request.setStatus("IN_PROGRESS"); + } else if (request.getStatus().equals("IN_PROGRESS")) { + request.setStatus("DONE"); + } else { + System.out.println("Request is already DONE."); + return; + } + + System.out.println("Updated request:"); + System.out.println(request); + } + + public static void viewResidentAccounts(ArrayList accounts) { + if (accounts.isEmpty()) { + System.out.println("No resident accounts found."); + return; + } + + System.out.println("\n--- RESIDENT ACCOUNTS ---"); + for (ResidentAccount account : accounts) { + System.out.println(account); + } + } + + public static void makePayment(ArrayList accounts, Scanner scan) { + if (accounts.isEmpty()) { + System.out.println("No resident accounts available."); + return; + } + + System.out.print("Enter apartment number: "); + String apartmentNumber = scan.nextLine(); + + ResidentAccount account = findAccount(accounts, apartmentNumber); + if (account == null) { + System.out.println("Account not found."); + return; + } + + System.out.print("Enter payment amount: "); + double amount = readDouble(scan); + + account.makePayment(amount); + System.out.println("Updated account:"); + System.out.println(account); + } + + public static void dailyReport(ArrayList requests, ArrayList accounts) { + int newCount = 0; + int inProgressCount = 0; + int doneCount = 0; + int maintenanceCount = 0; + int cleaningCount = 0; + + for (ServiceRequest request : requests) { + if (request.getStatus().equals("NEW")) { + newCount++; + } else if (request.getStatus().equals("IN_PROGRESS")) { + inProgressCount++; + } else if (request.getStatus().equals("DONE")) { + doneCount++; + } + + if (request.getRequestType().equals("Maintenance")) { + maintenanceCount++; + } else if (request.getRequestType().equals("Cleaning")) { + cleaningCount++; + } + } + + System.out.println("\n--- DAILY REPORT ---"); + System.out.println("Total Requests: " + requests.size()); + System.out.println("Maintenance Requests: " + maintenanceCount); + System.out.println("Cleaning Requests: " + cleaningCount); + System.out.println("NEW: " + newCount); + System.out.println("IN_PROGRESS: " + inProgressCount); + System.out.println("DONE: " + doneCount); + System.out.println("Resident Accounts: " + accounts.size()); + } + + public static ResidentAccount findAccount(ArrayList accounts, String apartmentNumber) { + for (ResidentAccount account : accounts) { + if (account.getApartmentNumber().equals(apartmentNumber)) { + return account; + } + } + return null; + } + + public static int readInt(Scanner scan) { + while (!scan.hasNextInt()) { + System.out.println("Please enter a valid whole number."); + scan.nextLine(); + } + int value = scan.nextInt(); + scan.nextLine(); + return value; + } - 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); + public static double readDouble(Scanner scan) { + while (!scan.hasNextDouble()) { + System.out.println("Please enter a valid number."); + scan.nextLine(); } + double value = scan.nextDouble(); + scan.nextLine(); + return value; } } \ No newline at end of file diff --git a/src/main/java/org/codedifferently/MaintenanceRequest.java b/src/main/java/org/codedifferently/MaintenanceRequest.java new file mode 100644 index 0000000..3c29184 --- /dev/null +++ b/src/main/java/org/codedifferently/MaintenanceRequest.java @@ -0,0 +1,59 @@ +package org.codedifferently; + +// MaintenanceRequest extends ServiceRequest +// This represents a repair or maintenance issue in an apartment +public class MaintenanceRequest extends ServiceRequest { + + // Type of maintenance issue (plumbing, electrical, etc.) + private String issueType; + + // Severity level (1–5) + private int issueSeverity; + + // Default constructor + public MaintenanceRequest() { + super(); // calls parent constructor + } + + // Constructor with details + public MaintenanceRequest(String tenantName, String apartmentNumber, String issueType, int issueSeverity) { + super(tenantName, apartmentNumber); + this.issueType = issueType; + this.issueSeverity = issueSeverity; + } + + // Overrides abstract method from ServiceRequest + @Override + public String getRequestType() { + return "Maintenance"; + } + + // Getter methods + public String getIssueType() { + return issueType; + } + + public int getIssueSeverity() { + return issueSeverity; + } + + // Setter methods + public void setIssueType(String issueType) { + this.issueType = issueType; + } + + public void setIssueSeverity(int issueSeverity) { + this.issueSeverity = issueSeverity; + } + + // Converts the object to a readable string + @Override + public String toString() { + return "Tenant: " + tenantName + + " | Apt: " + apartmentNumber + + " | Type: " + getRequestType() + + " | Issue: " + issueType + + " | Severity: " + issueSeverity + + " | Status: " + status; + } +} \ No newline at end of file diff --git a/src/main/java/org/codedifferently/README.md b/src/main/java/org/codedifferently/README.md new file mode 100644 index 0000000..67408c9 --- /dev/null +++ b/src/main/java/org/codedifferently/README.md @@ -0,0 +1,50 @@ +# Property Management Resident System + +A Java command-line application designed to help manage resident service requests in an apartment or housing complex. The system allows residents to submit service requests while management can track and organize them. + +--- + +## Sprint 1 — The Plan + +Our project is a **Property Management Resident System**, a Java application designed to help manage resident service requests in an apartment or housing complex. The goal of the program is to simulate a real property management system where residents can submit requests and management can track them. + +The program helps organize common resident needs such as **maintenance requests, cleaning requests, and resident account information** in one system instead of handling them manually. + +### Planned Features +- Creating and storing resident accounts +- Submitting maintenance requests +- Submitting cleaning requests +- Organizing services using an abstract `Service` class +- Displaying request details through a command-line interface + +### Planned Classes +- `ResidentAccount` +- `MaintenanceRequest` +- `CleaningRequest` +- `Service` (abstract class) + +### Work Distribution +We divided the work based on our strengths and previous experience. We also reused and adapted code from earlier projects to help build the system more efficiently. + +- **Corey**: Documented the sprint phases and built the `MaintenanceRequest` class. +- **Derwin**: Developed the `ResidentAccount`, `CleaningRequest`, and `Service` classes and worked on integrating the overall functionality. + +--- + +## Sprint 2 — The Build + +During this sprint, we built the foundation of the **Property Management Resident System** by combining and refactoring code from previous projects. We implemented the main class structure including `MaintenanceRequest`, `CleaningRequest`, `ResidentAccount`, and the abstract `Service` class. This structure helped organize the system so resident information and service requests are handled separately. + +Some parts of the project changed from our original plan. Instead of building everything from scratch, we reused and modified older code to fit the new system. This allowed us to focus more on integrating the classes and applying object-oriented design. + +One challenge was making code from different projects work together consistently. We had to adjust class structures, naming conventions, and logic so everything fit into one cohesive system. We addressed this by reviewing each class, identifying shared behaviors, and using inheritance through the `Service` abstract class to organize the program more effectively. + +--- + +## Sprint 3 — The Reflection + +One thing that works well in our program is the way it models a real property management system using separate classes with clear responsibilities. The `ResidentAccount` class manages resident information, while `MaintenanceRequest` and `CleaningRequest` handle different types of service requests. The abstract `Service` class helps organize shared behavior between request types. + +If we had more time, we would improve the system by adding features such as a better way to catch user input and stronger connections between residents and their service requests. We could also expand the command-line interface to make the program more interactive. + +Throughout this project, we used several Java concepts including **classes and objects, inheritance, abstract classes, constructors, and encapsulation**. This experience helped us better understand how to design and organize a larger program while applying object-oriented programming principles. \ No newline at end of file diff --git a/src/main/java/org/codedifferently/ResidentAccount.java b/src/main/java/org/codedifferently/ResidentAccount.java new file mode 100644 index 0000000..0edbe40 --- /dev/null +++ b/src/main/java/org/codedifferently/ResidentAccount.java @@ -0,0 +1,53 @@ +package org.codedifferently; + +// Represents a resident's account for billing and payments +public class ResidentAccount { + + private String residentName; + private String apartmentNumber; + private double balanceDue; + + // Constructor + public ResidentAccount(String residentName, String apartmentNumber, double balanceDue) { + this.residentName = residentName; + this.apartmentNumber = apartmentNumber; + this.balanceDue = balanceDue; + } + + // Getter methods + public String getResidentName() { + return residentName; + } + + public String getApartmentNumber() { + return apartmentNumber; + } + + public double getBalanceDue() { + return balanceDue; + } + + // Adds a charge to the resident's balance + public void addCharge(double amount) { + if (amount > 0) { + balanceDue += amount; + } + } + + // Allows resident to make a payment + public void makePayment(double amount) { + if (amount > 0 && amount <= balanceDue) { + balanceDue -= amount; + } else { + System.out.println("INVALID PAYMENT AMOUNT"); + } + } + + // Display account information + @Override + public String toString() { + return "Resident: " + residentName + + " | Apt: " + apartmentNumber + + " | Balance Due: $" + String.format("%.2f", balanceDue); + } +} \ No newline at end of file diff --git a/src/main/java/org/codedifferently/ServiceRequest.java b/src/main/java/org/codedifferently/ServiceRequest.java new file mode 100644 index 0000000..1168313 --- /dev/null +++ b/src/main/java/org/codedifferently/ServiceRequest.java @@ -0,0 +1,59 @@ +package org.codedifferently; + +// Abstract class representing a general service request. +// Other request types (Maintenance, Cleaning) will inherit from this. +public abstract class ServiceRequest { + + // Protected so subclasses can access these fields + protected String tenantName; + protected String apartmentNumber; + protected String status; + + // Default constructor + // Every new request starts with status NEW + public ServiceRequest() { + this.status = "NEW"; + } + + // Constructor used when tenant name and apartment number are known + public ServiceRequest(String tenantName, String apartmentNumber) { + this.tenantName = tenantName; + this.apartmentNumber = apartmentNumber; + this.status = "NEW"; + } + + // Getter methods + public String getTenantName() { + return tenantName; + } + + public String getApartmentNumber() { + return apartmentNumber; + } + + public String getStatus() { + return status; + } + + // Setter methods + public void setTenantName(String tenantName) { + this.tenantName = tenantName; + } + + public void setApartmentNumber(String apartmentNumber) { + this.apartmentNumber = apartmentNumber; + } + + // Only allow valid status updates + public void setStatus(String status) { + if (status.equals("NEW") || status.equals("IN_PROGRESS") || status.equals("DONE")) { + this.status = status; + } else { + System.out.println("INVALID STATUS UPDATE"); + } + } + + // Abstract method that subclasses must implement + // This allows different request types (Cleaning, Maintenance) + public abstract String getRequestType(); +} \ No newline at end of file