From 28997391200dd2452d055de33f5c1f1595712a5a Mon Sep 17 00:00:00 2001 From: BennettDeveloper Date: Fri, 20 Feb 2026 16:47:33 -0500 Subject: [PATCH 01/12] initial commit, project setup --- .../org/codedifferently/CarAppointment.java | 4 ++++ .../java/org/codedifferently/CarClinicApp.java | 11 +++++++++++ .../org/codedifferently/CarClinicSystem.java | 4 ++++ .../java/org/codedifferently/CarPatient.java | 4 ++++ src/main/java/org/codedifferently/Main.java | 17 ----------------- 5 files changed, 23 insertions(+), 17 deletions(-) create mode 100644 src/main/java/org/codedifferently/CarAppointment.java create mode 100644 src/main/java/org/codedifferently/CarClinicApp.java create mode 100644 src/main/java/org/codedifferently/CarClinicSystem.java create mode 100644 src/main/java/org/codedifferently/CarPatient.java delete mode 100644 src/main/java/org/codedifferently/Main.java diff --git a/src/main/java/org/codedifferently/CarAppointment.java b/src/main/java/org/codedifferently/CarAppointment.java new file mode 100644 index 0000000..2285704 --- /dev/null +++ b/src/main/java/org/codedifferently/CarAppointment.java @@ -0,0 +1,4 @@ +package org.codedifferently; + +public class CarAppointment { +} diff --git a/src/main/java/org/codedifferently/CarClinicApp.java b/src/main/java/org/codedifferently/CarClinicApp.java new file mode 100644 index 0000000..18da7ba --- /dev/null +++ b/src/main/java/org/codedifferently/CarClinicApp.java @@ -0,0 +1,11 @@ +package org.codedifferently; + +//TIP To Run code, press or +// click the icon in the gutter. +public class CarClinicApp { + public static void main(String[] args) { + + System.out.println("Test"); + + } +} \ No newline at end of file diff --git a/src/main/java/org/codedifferently/CarClinicSystem.java b/src/main/java/org/codedifferently/CarClinicSystem.java new file mode 100644 index 0000000..77c4bf3 --- /dev/null +++ b/src/main/java/org/codedifferently/CarClinicSystem.java @@ -0,0 +1,4 @@ +package org.codedifferently; + +public class CarClinicSystem { +} diff --git a/src/main/java/org/codedifferently/CarPatient.java b/src/main/java/org/codedifferently/CarPatient.java new file mode 100644 index 0000000..eb1f2fe --- /dev/null +++ b/src/main/java/org/codedifferently/CarPatient.java @@ -0,0 +1,4 @@ +package org.codedifferently; + +public class CarPatient { +} diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java deleted file mode 100644 index 435139b..0000000 --- a/src/main/java/org/codedifferently/Main.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.codedifferently; - -//TIP To Run code, press or -// click the icon in the gutter. -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); - } - } -} \ No newline at end of file From bb75b2ec218ea2a2036b7219e3a6710cb3c3b7a1 Mon Sep 17 00:00:00 2001 From: BennettDeveloper Date: Sun, 22 Feb 2026 17:34:06 -0500 Subject: [PATCH 02/12] feat: adding class data and main menu --- .../org/codedifferently/CarClinicApp.java | 19 +++++++++++++++++++ .../java/org/codedifferently/CarPatient.java | 7 +++++++ .../java/org/codedifferently/data/Car.java | 10 ++++++++++ 3 files changed, 36 insertions(+) create mode 100644 src/main/java/org/codedifferently/data/Car.java diff --git a/src/main/java/org/codedifferently/CarClinicApp.java b/src/main/java/org/codedifferently/CarClinicApp.java index 18da7ba..72601f3 100644 --- a/src/main/java/org/codedifferently/CarClinicApp.java +++ b/src/main/java/org/codedifferently/CarClinicApp.java @@ -7,5 +7,24 @@ public static void main(String[] args) { System.out.println("Test"); + + + CarClinicApp carClinicApp = new CarClinicApp(); + carClinicApp.handleMainMenu(); + } + + void handleMainMenu() { + System.out.println("Welcome to the CWW Auto Repair Shop."); + System.out.println("What would you like to do today?"); + + System.out.println("-------------------------------------"); + System.out.println("1. Add patient"); + System.out.println("2. View all patients"); + System.out.println("3. Check in patient"); + System.out.println("4. Search for patient"); + System.out.println("5. Exit"); + System.out.println("-------------------------------------"); + + } } \ No newline at end of file diff --git a/src/main/java/org/codedifferently/CarPatient.java b/src/main/java/org/codedifferently/CarPatient.java index eb1f2fe..303eefe 100644 --- a/src/main/java/org/codedifferently/CarPatient.java +++ b/src/main/java/org/codedifferently/CarPatient.java @@ -1,4 +1,11 @@ package org.codedifferently; +import org.codedifferently.data.Car; + public class CarPatient { + private String firstName; + private String lastName; + private String email; + private String phoneNumber; + public Car patientCar; } diff --git a/src/main/java/org/codedifferently/data/Car.java b/src/main/java/org/codedifferently/data/Car.java new file mode 100644 index 0000000..8948b70 --- /dev/null +++ b/src/main/java/org/codedifferently/data/Car.java @@ -0,0 +1,10 @@ +package org.codedifferently.data; + +public class Car { + + private String licensePlate; + private String model; + private int year; + private String color; + private int mileage; +} From 805409a21ce5a20a867d450fb417d590381c0b16 Mon Sep 17 00:00:00 2001 From: BennettDeveloper Date: Sun, 22 Feb 2026 18:28:13 -0500 Subject: [PATCH 03/12] feat: added nav menus for main menu and patient viewer menu --- .../org/codedifferently/CarClinicApp.java | 87 ++++++++++++++++--- .../org/codedifferently/CarClinicSystem.java | 13 +++ .../java/org/codedifferently/CarPatient.java | 4 + .../codedifferently/helpers/InputHandler.java | 27 ++++++ 4 files changed, 118 insertions(+), 13 deletions(-) create mode 100644 src/main/java/org/codedifferently/helpers/InputHandler.java diff --git a/src/main/java/org/codedifferently/CarClinicApp.java b/src/main/java/org/codedifferently/CarClinicApp.java index 72601f3..ed201d3 100644 --- a/src/main/java/org/codedifferently/CarClinicApp.java +++ b/src/main/java/org/codedifferently/CarClinicApp.java @@ -1,30 +1,91 @@ package org.codedifferently; +import org.codedifferently.helpers.InputHandler; + +import java.util.Scanner; + //TIP To Run code, press or // click the icon in the gutter. public class CarClinicApp { public static void main(String[] args) { - System.out.println("Test"); + CarClinicApp carClinicApp = new CarClinicApp(); + CarClinicSystem carClinicSystem = new CarClinicSystem(); + + carClinicApp.handleMainMenu(carClinicSystem); + } + void handleMainMenu(CarClinicSystem carClinicSystem) { - CarClinicApp carClinicApp = new CarClinicApp(); - carClinicApp.handleMainMenu(); + boolean inMainMenu = true; + while(inMainMenu) { + + System.out.println("Welcome to the CWW Auto Repair Shop."); + System.out.println("What would you like to do today?"); + + System.out.println("-------------------------------------"); + System.out.println("1. View Car Patients"); + System.out.println("2. View Car Appointments"); + System.out.println("3. Check Summary Reports"); + System.out.println("4. Exit"); + System.out.println("-------------------------------------"); + + //Call Static Method to handle Integer input + int scanInput = InputHandler.handleIntegerInput(); + + switch (scanInput) { + case 1: + handlePatientMenu(carClinicSystem); + break; + case 4: + inMainMenu = false; + System.out.println("Alright, have a nice day!"); + break; + default: + System.out.println("That's not an option on our menu! Please try again!"); + break; + } + } } - void handleMainMenu() { - System.out.println("Welcome to the CWW Auto Repair Shop."); - System.out.println("What would you like to do today?"); + void handlePatientMenu(CarClinicSystem carClinicSystem) { + + boolean inPatientMenu = true; + while(inPatientMenu) { + System.out.println("-------------------------------------"); + System.out.println("Patient Viewer"); + System.out.println("We appreciate your patience, Patient!"); + System.out.println("What would you like to do today?"); + System.out.println("-------------------------------------"); + System.out.println("1. Add patient"); + System.out.println("2. View all patients"); + System.out.println("3. Check in patient"); + System.out.println("4. Search for patient"); + System.out.println("5. Exit"); + System.out.println("-------------------------------------"); - System.out.println("-------------------------------------"); - System.out.println("1. Add patient"); - System.out.println("2. View all patients"); - System.out.println("3. Check in patient"); - System.out.println("4. Search for patient"); - System.out.println("5. Exit"); - System.out.println("-------------------------------------"); + int scanInput = InputHandler.handleIntegerInput(); + switch(scanInput) { + case 0: + break; + case 1: + break; + case 2: + break; + case 3: + break; + case 4: + break; + case 5: + System.out.println("Exiting out of Patient Menu!"); + inPatientMenu = false; + break; + default: + System.out.println("Thats not an option on our menu, please try again."); + } + } } } \ No newline at end of file diff --git a/src/main/java/org/codedifferently/CarClinicSystem.java b/src/main/java/org/codedifferently/CarClinicSystem.java index 77c4bf3..f7ee577 100644 --- a/src/main/java/org/codedifferently/CarClinicSystem.java +++ b/src/main/java/org/codedifferently/CarClinicSystem.java @@ -1,4 +1,17 @@ package org.codedifferently; +import java.util.ArrayList; + public class CarClinicSystem { + + private ArrayList carAppointments = new ArrayList<>(); + private ArrayList carPatients = new ArrayList<>(); + + public ArrayList getCarAppointments() { + return carAppointments; + } + + public ArrayList getCarPatients() { + return carPatients; + } } diff --git a/src/main/java/org/codedifferently/CarPatient.java b/src/main/java/org/codedifferently/CarPatient.java index 303eefe..582348a 100644 --- a/src/main/java/org/codedifferently/CarPatient.java +++ b/src/main/java/org/codedifferently/CarPatient.java @@ -3,9 +3,13 @@ import org.codedifferently.data.Car; public class CarPatient { + + private String patientID; private String firstName; private String lastName; private String email; private String phoneNumber; public Car patientCar; + + } diff --git a/src/main/java/org/codedifferently/helpers/InputHandler.java b/src/main/java/org/codedifferently/helpers/InputHandler.java new file mode 100644 index 0000000..5cf734a --- /dev/null +++ b/src/main/java/org/codedifferently/helpers/InputHandler.java @@ -0,0 +1,27 @@ +package org.codedifferently.helpers; + +import java.util.Scanner; + +public class InputHandler { + + public static int handleIntegerInput() { + Scanner scan = new Scanner(System.in); + int scanInput = 0; + boolean validScanInput = false; + //While loop to make sure user puts in the correct input + while(!validScanInput) { + //Call Scanner methods + try { + //Scanner method to collect input + scanInput = scan.nextInt(); + validScanInput = true; + } + catch (Exception e) { + //If user enters invalid input, the catch block will prevent errors. + System.out.println("Invalid input! Try typing a number instead of a String!"); + scan.next(); + } + } + return scanInput; + } +} From 6768c44d1c0b0f5f172250866c089ed63f444cd5 Mon Sep 17 00:00:00 2001 From: BennettDeveloper Date: Sun, 22 Feb 2026 19:17:54 -0500 Subject: [PATCH 04/12] feat: completed patient search functionality --- .../org/codedifferently/CarClinicApp.java | 8 +- .../java/org/codedifferently/CarPatient.java | 41 +++- .../codedifferently/helpers/InputHandler.java | 22 +++ .../helpers/PatientHandler.java | 178 ++++++++++++++++++ 4 files changed, 246 insertions(+), 3 deletions(-) create mode 100644 src/main/java/org/codedifferently/helpers/PatientHandler.java diff --git a/src/main/java/org/codedifferently/CarClinicApp.java b/src/main/java/org/codedifferently/CarClinicApp.java index ed201d3..a68f26c 100644 --- a/src/main/java/org/codedifferently/CarClinicApp.java +++ b/src/main/java/org/codedifferently/CarClinicApp.java @@ -1,6 +1,7 @@ package org.codedifferently; import org.codedifferently.helpers.InputHandler; +import org.codedifferently.helpers.PatientHandler; import java.util.Scanner; @@ -67,16 +68,19 @@ void handlePatientMenu(CarClinicSystem carClinicSystem) { int scanInput = InputHandler.handleIntegerInput(); + PatientHandler patientHandler = new PatientHandler(); + switch(scanInput) { - case 0: - break; case 1: + patientHandler.promptNewPatient(carClinicSystem); break; case 2: + patientHandler.viewAllPatients(carClinicSystem); break; case 3: break; case 4: + patientHandler.printSearchedPatient(carClinicSystem); break; case 5: System.out.println("Exiting out of Patient Menu!"); diff --git a/src/main/java/org/codedifferently/CarPatient.java b/src/main/java/org/codedifferently/CarPatient.java index 582348a..8064f7f 100644 --- a/src/main/java/org/codedifferently/CarPatient.java +++ b/src/main/java/org/codedifferently/CarPatient.java @@ -9,7 +9,46 @@ public class CarPatient { private String lastName; private String email; private String phoneNumber; - public Car patientCar; + private boolean checkedIn; + //public Car patientCar; + public CarPatient(String patientID, String firstName, String lastName, + String email, String phoneNumber) { + this.patientID = patientID; + this.firstName = firstName; + this.lastName = lastName; + this.email = email; + this.phoneNumber = phoneNumber; + this.checkedIn = false; + //this.patientCar = patientCar; + } + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + + public String getEmail() { + return email; + } + + public String getPhoneNumber() { + return phoneNumber; + } + + public String getPatientID() { + return patientID; + } + + public boolean isCheckedIn() { + return checkedIn; + } + + public void setCheckedIn(boolean checkedIn) { + this.checkedIn = checkedIn; + } } diff --git a/src/main/java/org/codedifferently/helpers/InputHandler.java b/src/main/java/org/codedifferently/helpers/InputHandler.java index 5cf734a..b397763 100644 --- a/src/main/java/org/codedifferently/helpers/InputHandler.java +++ b/src/main/java/org/codedifferently/helpers/InputHandler.java @@ -24,4 +24,26 @@ public static int handleIntegerInput() { } return scanInput; } + + public static String handleStringInput() { + Scanner scan = new Scanner(System.in); + String scanInput = ""; + boolean validScanInput = false; + //While loop to make sure user puts in the correct input + while(!validScanInput) { + //Call Scanner methods + try { + //Scanner method to collect input + scanInput = scan.nextLine(); + validScanInput = true; + } + catch (Exception e) { + //If user enters invalid input, the catch block will prevent errors. + System.out.println("Invalid input! Try typing a valid String!"); + scan.next(); + } + } + return scanInput; + } + } diff --git a/src/main/java/org/codedifferently/helpers/PatientHandler.java b/src/main/java/org/codedifferently/helpers/PatientHandler.java new file mode 100644 index 0000000..d6f296b --- /dev/null +++ b/src/main/java/org/codedifferently/helpers/PatientHandler.java @@ -0,0 +1,178 @@ +package org.codedifferently.helpers; +import org.codedifferently.CarClinicSystem; +import org.codedifferently.CarPatient; + +import java.util.UUID; + +public class PatientHandler { + + public void promptNewPatient(CarClinicSystem carClinicSystem) { + + //Prompt user for information. (firstname, lastname, email, phoneNumber) + System.out.println("What is your first name?"); + String firstName = InputHandler.handleStringInput(); + + System.out.println("What is your last name?"); + String lastName = InputHandler.handleStringInput(); + + System.out.println("What's your Email Address?"); + String email = InputHandler.handleStringInput(); + + System.out.println("What's your Phone Number?"); + String phoneNumber = InputHandler.handleStringInput(); + + System.out.println("Awesome, here's your Unique ID, do not share this with ANYONE!"); + String uniqueID = UUID.randomUUID().toString().substring(0, 6); + System.out.println(uniqueID); + + //Make New Car Patient. + CarPatient carPatient = new CarPatient(uniqueID, firstName, lastName, email, phoneNumber); + + //Add new Car Patient to Car Patient Array List. + carClinicSystem.getCarPatients().add(carPatient); + + } + + public void viewAllPatients(CarClinicSystem carClinicSystem) { + System.out.println("--------------------------------"); + System.out.println("****************************"); + System.out.println("VIEWING ALL PATIENTS"); + + //If no patients, print extra message + if(carClinicSystem.getCarPatients().isEmpty()) { + System.out.println("THERE ARE NO PATIENTS IN THE SYSTEM CURRENTLY"); + } + + //Loop through all car patients, print each of them out. + for(int i = 0; i < carClinicSystem.getCarPatients().size(); i++) { + + //print every field of CarPatient + System.out.print((i+1) + ". ("); + System.out.print(carClinicSystem.getCarPatients().get(i).getPatientID()+ ") "); + System.out.print(carClinicSystem.getCarPatients().get(i).getLastName() + ", "); + System.out.print(carClinicSystem.getCarPatients().get(i).getFirstName() + " | "); + System.out.print(carClinicSystem.getCarPatients().get(i).getEmail() + " | "); + System.out.print(carClinicSystem.getCarPatients().get(i).getPhoneNumber()); + + String checkedInMsg = (carClinicSystem.getCarPatients().get(i).isCheckedIn() ? "Yes" : " No"); + System.out.print("Checked In: " + checkedInMsg); + System.out.println(); + } + + System.out.println("***************************"); + System.out.println("---------------------------------"); + + System.out.println("Type any key to continue..."); + InputHandler.handleStringInput(); + + } + + + public CarPatient searchForPatient(CarClinicSystem carClinicSystem) { + System.out.println("SEARCHING FOR PATIENT!!"); + System.out.println("Enter the Patients Last Name:"); + + String lastNameInput = InputHandler.handleStringInput(); + CarPatient searchedPatient = null; + + //Loop through all car patients, if theres 1-match. retrieve him + int foundPatientCount = 0; + + for(int i = 0; i < carClinicSystem.getCarPatients().size(); i++) { + + //Keep a counter if we find a match, if we get more than one match. try + //to check for first name now to distinguish the two matches. + if(lastNameInput.equals(carClinicSystem.getCarPatients().get(i).getLastName())) { + searchedPatient = carClinicSystem.getCarPatients().get(i); + foundPatientCount++; + } + } + //If one exact match, return the result! + if(foundPatientCount <= 1) { + return searchedPatient; + } + + //else, we will check first names now + System.out.println("Enter the Patients First Name:"); + searchedPatient = null; + foundPatientCount = 0; + String firstNameInput = InputHandler.handleStringInput(); + for(int i = 0; i < carClinicSystem.getCarPatients().size(); i++) { + + //Keep a counter if we find a match, if we get more than one match. try + //to check for first name now to distinguish the two matches. + if(firstNameInput.equals(carClinicSystem.getCarPatients().get(i).getFirstName())) { + searchedPatient = carClinicSystem.getCarPatients().get(i); + foundPatientCount++; + } + } + + //If one exact match, return the result! + if(foundPatientCount <= 1) { + return searchedPatient; + } + + //Finally, if last name AND first name grants duplicate result, then ask user for their + //unique ID + + System.out.println("Enter the Patients UUID:"); + searchedPatient = null; + foundPatientCount = 0; + String uuIDInput = InputHandler.handleStringInput(); + for(int i = 0; i < carClinicSystem.getCarPatients().size(); i++) { + + //Keep a counter if we find a match, if we get more than one match. try + //to check for first name now to distinguish the two matches. + if(uuIDInput.equals(carClinicSystem.getCarPatients().get(i).getPatientID())) { + searchedPatient = carClinicSystem.getCarPatients().get(i); + foundPatientCount++; + } + } + return searchedPatient; + } + + //Print searched patient, call helper to help with results. this one just prints + //what it finds. + public void printSearchedPatient(CarClinicSystem carClinicSystem) { + + CarPatient searchedPatient = searchForPatient(carClinicSystem); + + if(searchedPatient == null) { + System.out.println("Searched Patient did not exist! Please try again!"); + } + else { + System.out.println("-----------------------------------------"); + System.out.println("Patient FOUND: "); + System.out.println("Name: " + searchedPatient.getFirstName() + + ", " +searchedPatient.getLastName()); + System.out.println("Email: " + searchedPatient.getEmail()); + System.out.println("Phone Number: " + searchedPatient.getPhoneNumber()); + System.out.println("UUID: " + searchedPatient.getPatientID()); + System.out.println("Checked-In" + (searchedPatient.isCheckedIn() ? "Yes" : "No")); + System.out.println("Type any key to continue..."); + InputHandler.handleStringInput(); + System.out.println("-------------------------------------"); + } + } + + //We use the search functionality to get the patient checked-in. + public void checkInPatient(CarClinicSystem carClinicSystem) { + System.out.println("---------------------------------------"); + System.out.println("Alright, checking in a patient!!"); + System.out.println("But first we need to locate the patient!"); + + CarPatient searchedPatient = searchForPatient(carClinicSystem); + + if(searchedPatient == null) { + System.out.println("Searched Patient did not exist! Please try again!"); + } + else { + System.out.println("Patient " + searchedPatient.getLastName() + + ", " + searchedPatient.getFirstName() + " (" + + searchedPatient.getPatientID() + + ") is now checked in!"); + searchedPatient.setCheckedIn(true); + } + } + +} From 4bed7f71cd8669347bcfd53198bc470fcd7c16a9 Mon Sep 17 00:00:00 2001 From: BennettDeveloper Date: Sun, 22 Feb 2026 19:20:21 -0500 Subject: [PATCH 05/12] feat: finished patient check-in functionality --- src/main/java/org/codedifferently/CarClinicApp.java | 1 + src/main/java/org/codedifferently/helpers/PatientHandler.java | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/codedifferently/CarClinicApp.java b/src/main/java/org/codedifferently/CarClinicApp.java index a68f26c..d81b85f 100644 --- a/src/main/java/org/codedifferently/CarClinicApp.java +++ b/src/main/java/org/codedifferently/CarClinicApp.java @@ -78,6 +78,7 @@ void handlePatientMenu(CarClinicSystem carClinicSystem) { patientHandler.viewAllPatients(carClinicSystem); break; case 3: + patientHandler.checkInPatient(carClinicSystem); break; case 4: patientHandler.printSearchedPatient(carClinicSystem); diff --git a/src/main/java/org/codedifferently/helpers/PatientHandler.java b/src/main/java/org/codedifferently/helpers/PatientHandler.java index d6f296b..890f78d 100644 --- a/src/main/java/org/codedifferently/helpers/PatientHandler.java +++ b/src/main/java/org/codedifferently/helpers/PatientHandler.java @@ -52,7 +52,7 @@ public void viewAllPatients(CarClinicSystem carClinicSystem) { System.out.print(carClinicSystem.getCarPatients().get(i).getLastName() + ", "); System.out.print(carClinicSystem.getCarPatients().get(i).getFirstName() + " | "); System.out.print(carClinicSystem.getCarPatients().get(i).getEmail() + " | "); - System.out.print(carClinicSystem.getCarPatients().get(i).getPhoneNumber()); + System.out.print(carClinicSystem.getCarPatients().get(i).getPhoneNumber() + " | "); String checkedInMsg = (carClinicSystem.getCarPatients().get(i).isCheckedIn() ? "Yes" : " No"); System.out.print("Checked In: " + checkedInMsg); @@ -148,7 +148,7 @@ public void printSearchedPatient(CarClinicSystem carClinicSystem) { System.out.println("Email: " + searchedPatient.getEmail()); System.out.println("Phone Number: " + searchedPatient.getPhoneNumber()); System.out.println("UUID: " + searchedPatient.getPatientID()); - System.out.println("Checked-In" + (searchedPatient.isCheckedIn() ? "Yes" : "No")); + System.out.println("Checked-In: " + (searchedPatient.isCheckedIn() ? "Yes" : "No")); System.out.println("Type any key to continue..."); InputHandler.handleStringInput(); System.out.println("-------------------------------------"); From b04848aa56e6a750ab91caba8f4e56be85940937 Mon Sep 17 00:00:00 2001 From: wilfredainsworth Date: Sun, 22 Feb 2026 22:36:34 -0500 Subject: [PATCH 06/12] Car Appointment class built --- Mechanic Shop/.idea/misc.xml | 6 ++ Mechanic Shop/.idea/modules.xml | 8 +++ Mechanic Shop/.idea/workspace.xml | 66 +++++++++++++++++ .../org/codedifferently/CarAppointment.java | 71 +++++++++++++++++++ .../org/codedifferently/CarClinicApp.java | 2 + 5 files changed, 153 insertions(+) create mode 100644 Mechanic Shop/.idea/misc.xml create mode 100644 Mechanic Shop/.idea/modules.xml create mode 100644 Mechanic Shop/.idea/workspace.xml diff --git a/Mechanic Shop/.idea/misc.xml b/Mechanic Shop/.idea/misc.xml new file mode 100644 index 0000000..7b50ef4 --- /dev/null +++ b/Mechanic Shop/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Mechanic Shop/.idea/modules.xml b/Mechanic Shop/.idea/modules.xml new file mode 100644 index 0000000..c8c8ab4 --- /dev/null +++ b/Mechanic Shop/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Mechanic Shop/.idea/workspace.xml b/Mechanic Shop/.idea/workspace.xml new file mode 100644 index 0000000..4e468fb --- /dev/null +++ b/Mechanic Shop/.idea/workspace.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1771806406753 + + + + + + + + file://$PROJECT_DIR$/src/Main.java + 10 + + + + + \ No newline at end of file diff --git a/src/main/java/org/codedifferently/CarAppointment.java b/src/main/java/org/codedifferently/CarAppointment.java index 2285704..7afe12a 100644 --- a/src/main/java/org/codedifferently/CarAppointment.java +++ b/src/main/java/org/codedifferently/CarAppointment.java @@ -1,4 +1,75 @@ package org.codedifferently; +import java.sql.Array; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.util.ArrayList; + public class CarAppointment { + private static final LocalTime OPEN_TIME = LocalTime.of(7,0); + private static final LocalTime CLOSE_TIME = LocalTime.of(21,0); + private static final LocalTime LAST_APPOINTMENT = LocalTime.of(20,0); + + private CarPatient carPatient; + private LocalDateTime apptDateTime; + private String serviceType; + + private boolean isDuringBusinessHours(LocalDateTime apptDateTime){ + LocalTime time = apptDateTime.toLocalTime(); + return time.isAfter(OPEN_TIME) && time.isBefore(CLOSE_TIME); + } + public CarAppointment(CarPatient carPatient, LocalDateTime apptDateTime, String serviceType){ + if(isDuringBusinessHours(apptDateTime)){ + this.carPatient = carPatient; + this.apptDateTime = apptDateTime; + this.serviceType= serviceType; + } else { + throw new IllegalArgumentException("Appointment must be between our business hours of 7am-9pm"); + } + } + + public CarAppointment(CarPatient carPatient, LocalDateTime apptDateTime){ + if(isDuringBusinessHours(apptDateTime)){ + this.carPatient = carPatient; + this.apptDateTime = apptDateTime; + } else { + throw new IllegalArgumentException("Appointment must be between our business hours of 7am-9pm"); + } + } + + public LocalDateTime getApptDateTime() { + return apptDateTime; + } + + public void setApptDateTime(LocalDateTime apptDateTime) { + this.apptDateTime = apptDateTime; + } + + public String getServiceType() { + return serviceType; + } + + public void setServiceType(String serviceType) { + this.serviceType = serviceType; + } + + public CarPatient getCarPatient() { + return carPatient; + } + + public void setCarPatient(CarPatient carPatient) { + this.carPatient = carPatient; + } + + /*if () + String[] daysOfWeek = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}; + open 7am-9pm daily (14hours/day) + int[] weekdayHours = new int [13]; + ArrayList apptSlots = new ArrayList<>(); + + + public void makeAppt(){ +*/ + + } diff --git a/src/main/java/org/codedifferently/CarClinicApp.java b/src/main/java/org/codedifferently/CarClinicApp.java index d81b85f..513f946 100644 --- a/src/main/java/org/codedifferently/CarClinicApp.java +++ b/src/main/java/org/codedifferently/CarClinicApp.java @@ -39,6 +39,8 @@ void handleMainMenu(CarClinicSystem carClinicSystem) { case 1: handlePatientMenu(carClinicSystem); break; + case 2: + case 4: inMainMenu = false; System.out.println("Alright, have a nice day!"); From 947ceec998bf5b3850c1a83ea9464909b0b08822 Mon Sep 17 00:00:00 2001 From: whblue261 Date: Sun, 22 Feb 2026 22:41:19 -0500 Subject: [PATCH 07/12] update car appointment and shop scheduler --- .../org/codedifferently/CarAppointment.java | 27 +++++- .../org/codedifferently/ShopScheduler.java | 83 +++++++++++++++++++ 2 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/codedifferently/ShopScheduler.java diff --git a/src/main/java/org/codedifferently/CarAppointment.java b/src/main/java/org/codedifferently/CarAppointment.java index 2285704..2f0ff1a 100644 --- a/src/main/java/org/codedifferently/CarAppointment.java +++ b/src/main/java/org/codedifferently/CarAppointment.java @@ -1,4 +1,29 @@ package org.codedifferently; public class CarAppointment { -} + // The customer who booked + private CarPatient customer; + // Type of repair + private String serviceType; + // Index of time slot in the schedule + private int slotIndex; + //The constructor w each contract + public CarAppointment(CarPatient customer, String serviceType, int slotIndex) { + this.customer = customer; + this.serviceType = serviceType; + this.slotIndex = slotIndex; + } + + public CarPatient getCustomer() { + return customer; + } + + public String getServiceType() { + return serviceType; + } + + public int getSlotIndex() { + return slotIndex; + } + } + diff --git a/src/main/java/org/codedifferently/ShopScheduler.java b/src/main/java/org/codedifferently/ShopScheduler.java new file mode 100644 index 0000000..6409a33 --- /dev/null +++ b/src/main/java/org/codedifferently/ShopScheduler.java @@ -0,0 +1,83 @@ +package org.codedifferently; +import java.util.ArrayList; + +public class ShopScheduler { + + // Array representing available time slots for the day + private final String[] timeSlots = { + "8:00 AM", "9:00 AM", "10:00 AM", "11:00 AM", + "12:00 PM", "1:00 PM", "2:00 PM", "3:00 PM", "4:00 PM" + }; + + // Store appointments using ArrayList + private ArrayList appointments = new ArrayList<>(); + + public String[] getTimeSlots() { + return timeSlots; + } + + // Check if a slot is already booked + public boolean isSlotBooked(int slotIndex) { + for (CarAppointment appt : appointments) { + if (appt.getSlotIndex() == slotIndex) { + return true; // Slot is taken + } + } + return false; // Slot is available + } + + // Schedule an appointment + public boolean scheduleAppointment(CarPatient customer, String serviceType, int slotIndex) { + + // check for timeSlot range + if (slotIndex < 0 || slotIndex >= timeSlots.length) { + return false; + } + + // Prevent double booking + if (isSlotBooked(slotIndex)) { + return false; + } + + CarAppointment newAppt = new CarAppointment(customer, serviceType, slotIndex); + appointments.add(newAppt); + return true; + } + + // Cancel appointment by timeSlot + public boolean cancelAppointment(int slotIndex) { + for (int i = 0; i < appointments.size(); i++) { + if (appointments.get(i).getSlotIndex() == slotIndex) { + appointments.remove(i); + return true; + } + } + return false; + } + + // Print full schedule + public void printSchedule() { + System.out.println("\n=== CWW Auto Repair Shop Daily Schedule ==="); + + for (int i = 0; i < timeSlots.length; i++) { + + CarAppointment found = null; + + for (CarAppointment appt : appointments) { + if (appt.getSlotIndex() == i) { + found = appt; + break; + } + } + + if (found == null) { + System.out.println((i + 1) + ") " + timeSlots[i] + " - AVAILABLE"); + } else { + System.out.println((i + 1) + ") " + timeSlots[i] + + " - " + found.getCustomer().getFirstName() + + " (" + found.getServiceType() + ")"); + } + } + } + } + From 5fb9dc354c78a4255da5b09b992f62439dac78cd Mon Sep 17 00:00:00 2001 From: BennettDeveloper Date: Sun, 22 Feb 2026 23:32:04 -0500 Subject: [PATCH 08/12] fix: implementing new time slot class --- .../org/codedifferently/CarAppointment.java | 37 +++++++++++-------- .../org/codedifferently/data/TimeSlot.java | 26 +++++++++++++ 2 files changed, 47 insertions(+), 16 deletions(-) create mode 100644 src/main/java/org/codedifferently/data/TimeSlot.java diff --git a/src/main/java/org/codedifferently/CarAppointment.java b/src/main/java/org/codedifferently/CarAppointment.java index 7afe12a..8b55cea 100644 --- a/src/main/java/org/codedifferently/CarAppointment.java +++ b/src/main/java/org/codedifferently/CarAppointment.java @@ -1,5 +1,7 @@ package org.codedifferently; +import org.codedifferently.data.TimeSlot; + import java.sql.Array; import java.time.LocalDateTime; import java.time.LocalTime; @@ -11,38 +13,41 @@ public class CarAppointment { private static final LocalTime LAST_APPOINTMENT = LocalTime.of(20,0); private CarPatient carPatient; - private LocalDateTime apptDateTime; + private TimeSlot timeSlot; + private String serviceType; - private boolean isDuringBusinessHours(LocalDateTime apptDateTime){ - LocalTime time = apptDateTime.toLocalTime(); - return time.isAfter(OPEN_TIME) && time.isBefore(CLOSE_TIME); + private boolean isDuringBusinessHours(TimeSlot timeSlot){ + LocalTime startTime = timeSlot.getStart().toLocalTime(); + LocalTime endTime = timeSlot.getEnd().toLocalTime(); + + return startTime.isAfter(OPEN_TIME) && endTime.isBefore(CLOSE_TIME); } - public CarAppointment(CarPatient carPatient, LocalDateTime apptDateTime, String serviceType){ - if(isDuringBusinessHours(apptDateTime)){ + public CarAppointment(CarPatient carPatient, TimeSlot timeSlot, String serviceType){ + if(isDuringBusinessHours(timeSlot)){ this.carPatient = carPatient; - this.apptDateTime = apptDateTime; + this.timeSlot = timeSlot; this.serviceType= serviceType; } else { - throw new IllegalArgumentException("Appointment must be between our business hours of 7am-9pm"); + System.out.println("Appointment must be between our business hours of 7am-9pm"); } } - public CarAppointment(CarPatient carPatient, LocalDateTime apptDateTime){ - if(isDuringBusinessHours(apptDateTime)){ + public CarAppointment(CarPatient carPatient, TimeSlot timeSlot){ + if(isDuringBusinessHours(timeSlot)){ this.carPatient = carPatient; - this.apptDateTime = apptDateTime; + this.timeSlot = timeSlot; } else { - throw new IllegalArgumentException("Appointment must be between our business hours of 7am-9pm"); + System.out.println("Appointment must be between our business hours of 7am-9pm"); } } - public LocalDateTime getApptDateTime() { - return apptDateTime; + public TimeSlot getTimeSlot() { + return timeSlot; } - public void setApptDateTime(LocalDateTime apptDateTime) { - this.apptDateTime = apptDateTime; + public void setTimeSlot(TimeSlot timeSlot) { + this.timeSlot = timeSlot; } public String getServiceType() { diff --git a/src/main/java/org/codedifferently/data/TimeSlot.java b/src/main/java/org/codedifferently/data/TimeSlot.java new file mode 100644 index 0000000..a8b16b9 --- /dev/null +++ b/src/main/java/org/codedifferently/data/TimeSlot.java @@ -0,0 +1,26 @@ +package org.codedifferently.data; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.Duration; + +public class TimeSlot { + private final LocalDateTime start; + private final LocalDateTime end; + + public TimeSlot(LocalDateTime start, LocalDateTime end) { + this.start = start; + this.end = end; + } + + public LocalDateTime getStart() { + return start; + } + + public LocalDateTime getEnd() { + return end; + } + + public Duration getDuration() { + return Duration.between(start, end); + } +} From 6b6d88354c1914ab3542dd532fc439f9a6bf5fc3 Mon Sep 17 00:00:00 2001 From: BennettDeveloper Date: Mon, 23 Feb 2026 01:00:02 -0500 Subject: [PATCH 09/12] feat: Added Appointment viewer functionality --- .../org/codedifferently/CarAppointment.java | 19 +++-- .../org/codedifferently/CarClinicApp.java | 58 ++++++++++++- .../org/codedifferently/ShopScheduler.java | 82 +++++++++++-------- .../helpers/PatientHandler.java | 4 +- 4 files changed, 119 insertions(+), 44 deletions(-) diff --git a/src/main/java/org/codedifferently/CarAppointment.java b/src/main/java/org/codedifferently/CarAppointment.java index 20b1200..b8f3c9d 100644 --- a/src/main/java/org/codedifferently/CarAppointment.java +++ b/src/main/java/org/codedifferently/CarAppointment.java @@ -6,9 +6,12 @@ import java.time.LocalDateTime; import java.time.LocalTime; import java.util.ArrayList; +import java.util.UUID; public class CarAppointment { + private String appointmentID; + private static final LocalTime OPEN_TIME = LocalTime.of(7,0); private static final LocalTime CLOSE_TIME = LocalTime.of(21,0); private static final LocalTime LAST_APPOINTMENT = LocalTime.of(20,0); @@ -18,20 +21,17 @@ public class CarAppointment { private String serviceType; - private boolean isDuringBusinessHours(TimeSlot timeSlot){ + public boolean isDuringBusinessHours(TimeSlot timeSlot){ LocalTime startTime = timeSlot.getStart().toLocalTime(); LocalTime endTime = timeSlot.getEnd().toLocalTime(); return startTime.isAfter(OPEN_TIME) && endTime.isBefore(CLOSE_TIME); } public CarAppointment(CarPatient carPatient, TimeSlot timeSlot, String serviceType){ - if(isDuringBusinessHours(timeSlot)){ this.carPatient = carPatient; this.timeSlot = timeSlot; this.serviceType= serviceType; - } else { - System.out.println("Appointment must be between our business hours of 7am-9pm"); - } + appointmentID = UUID.randomUUID().toString().substring(0, 6); } public CarAppointment(CarPatient carPatient, TimeSlot timeSlot){ @@ -43,6 +43,14 @@ public CarAppointment(CarPatient carPatient, TimeSlot timeSlot){ } } + public String getAppointmentID() { + return appointmentID; + } + + public void setAppointmentID(String appointmentID) { + this.appointmentID = appointmentID; + } + public TimeSlot getTimeSlot() { return timeSlot; } @@ -79,4 +87,3 @@ public void makeAppt(){ } ->>>>>>> d6d1dc034c29286415d4af47d7a7fba793f14ae5 diff --git a/src/main/java/org/codedifferently/CarClinicApp.java b/src/main/java/org/codedifferently/CarClinicApp.java index 513f946..76a226e 100644 --- a/src/main/java/org/codedifferently/CarClinicApp.java +++ b/src/main/java/org/codedifferently/CarClinicApp.java @@ -1,5 +1,6 @@ package org.codedifferently; +import org.codedifferently.data.TimeSlot; import org.codedifferently.helpers.InputHandler; import org.codedifferently.helpers.PatientHandler; @@ -40,7 +41,8 @@ void handleMainMenu(CarClinicSystem carClinicSystem) { handlePatientMenu(carClinicSystem); break; case 2: - + handleAppointmentMenu(carClinicSystem); + break; case 4: inMainMenu = false; System.out.println("Alright, have a nice day!"); @@ -95,4 +97,58 @@ void handlePatientMenu(CarClinicSystem carClinicSystem) { } } + + void handleAppointmentMenu(CarClinicSystem carClinicSystem) { + + boolean inAppointmentMenu = true; + while(inAppointmentMenu) { + System.out.println("-------------------------------------"); + System.out.println("Appointment Viewer"); + System.out.println("You have reached A POINT meant in time."); + System.out.println("What would you like to do today?"); + System.out.println("-------------------------------------"); + System.out.println("1. View Timeslots"); + System.out.println("2. Schedule an appointment"); + System.out.println("3. Cancel an appointment."); + System.out.println("4. Exit"); + System.out.println("-------------------------------------"); + + int scanInput = InputHandler.handleIntegerInput(); + + PatientHandler patientHandler = new PatientHandler(); + + ShopScheduler shopScheduler = new ShopScheduler(); + + switch(scanInput) { + case 1: + shopScheduler.printSchedule(carClinicSystem); + break; + case 2: + CarPatient patient = patientHandler.searchForPatient(carClinicSystem); + + if(patient == null) { + System.out.println("Patient was not found!!!"); + //Create new patient if not found. + patient = patientHandler.promptNewPatient(carClinicSystem); + } + TimeSlot timeSlot = shopScheduler.promptTimeSlot(); + String serviceType = shopScheduler.promptServiceType(); + + shopScheduler.scheduleAppointment(carClinicSystem, patient, timeSlot, serviceType); + break; + case 3: + System.out.println("Give me the appointment ID that you want to cancel: "); + String appointmentID = InputHandler.handleStringInput(); + shopScheduler.cancelAppointment(carClinicSystem, appointmentID); + break; + case 4: + System.out.println("Exiting out of Patient Menu!"); + inAppointmentMenu = false; + break; + default: + System.out.println("Thats not an option on our menu, please try again."); + } + } + + } } \ No newline at end of file diff --git a/src/main/java/org/codedifferently/ShopScheduler.java b/src/main/java/org/codedifferently/ShopScheduler.java index f38585f..a469741 100644 --- a/src/main/java/org/codedifferently/ShopScheduler.java +++ b/src/main/java/org/codedifferently/ShopScheduler.java @@ -1,28 +1,19 @@ package org.codedifferently; +import org.codedifferently.data.TimeSlot; +import org.codedifferently.helpers.InputHandler; + import java.time.LocalDate; import java.time.LocalDateTime; import java.time.chrono.ChronoLocalDate; import java.util.ArrayList; +import java.util.UUID; public class ShopScheduler { - // Array representing available time slots for the day - private final String[] timeSlots = { - "8:00 AM", "9:00 AM", "10:00 AM", "11:00 AM", - "12:00 PM", "1:00 PM", "2:00 PM", "3:00 PM", "4:00 PM" - }; - - // Store appointments using ArrayList - private ArrayList appointments = new ArrayList<>(); - - public String[] getTimeSlots() { - return timeSlots; - } - // Check if a slot is already booked - public boolean isSlotBooked(int slotIndex) { - for (CarAppointment appt : appointments) { - if (1 == slotIndex) { + public boolean isSlotBooked(CarClinicSystem carClinicSystem, String appointmentID) { + for (CarAppointment appt : carClinicSystem.getCarAppointments()) { + if (appt.getAppointmentID().equals(appointmentID)) { return true; // Slot is taken } } @@ -30,43 +21,42 @@ public boolean isSlotBooked(int slotIndex) { } // Schedule an appointment - public boolean scheduleAppointment(CarPatient customer, String serviceType, int slotIndex) { + public boolean scheduleAppointment(CarClinicSystem carClinicSystem, CarPatient customer, TimeSlot timeSlot, String serviceType) { - // check for timeSlot range - if (slotIndex < 0 || slotIndex >= timeSlots.length) { - return false; - } + CarAppointment newAppt = new CarAppointment(customer, timeSlot, "Oil Change"); // Prevent double booking - if (isSlotBooked(slotIndex)) { + if (isSlotBooked(carClinicSystem, newAppt.getAppointmentID())) { return false; } - LocalDateTime currentDateTime = LocalDateTime.now(); - CarAppointment newAppt = new CarAppointment(customer,currentDateTime, "Oil Change"); - appointments.add(newAppt); + + carClinicSystem.getCarAppointments().add(newAppt); return true; } // Cancel appointment by timeSlot - public boolean cancelAppointment(int slotIndex) { - for (int i = 0; i < appointments.size(); i++) { - if (1 == slotIndex) { - appointments.remove(i); + public boolean cancelAppointment(CarClinicSystem carClinicSystem, String appointmentID) { + + for(int i = 0; i < carClinicSystem.getCarAppointments().size(); i++) { + + if(carClinicSystem.getCarAppointments().get(i).equals(appointmentID)) { + carClinicSystem.getCarAppointments().remove(i); return true; } } return false; + } // Print full schedule - public void printSchedule() { + public void printSchedule(CarClinicSystem carClinicSystem) { System.out.println("\n=== CWW Auto Repair Shop Daily Schedule ==="); - for (int i = 0; i < timeSlots.length; i++) { + for (int i = 0; i < carClinicSystem.getCarAppointments().size(); i++) { CarAppointment found = null; - for (CarAppointment appt : appointments) { + for (CarAppointment appt : carClinicSystem.getCarAppointments()) { if (1 == i) { found = appt; break; @@ -74,13 +64,33 @@ public void printSchedule() { } if (found == null) { - System.out.println((i + 1) + ") " + timeSlots[i] + " - AVAILABLE"); + System.out.println((i + 1) + " - AVAILABLE"); } else { - // System.out.println((i + 1) + ") " + timeSlots[i] + - // " - " + found.getCustomer().getFirstName() + - // " (" + found.getServiceType() + ")"); + System.out.println((i + 1) + ") " + found.getTimeSlot().getStart() + + " - " + found.getTimeSlot().getEnd()+ + " (" + found.getServiceType() + ")"); } } } + + public TimeSlot promptTimeSlot() { + System.out.println("Give me the Start Time:"); + int startTime = InputHandler.handleIntegerInput(); + + int endTime = InputHandler.handleIntegerInput(); + + LocalDateTime startDateTime = LocalDate.now().atTime(startTime, 0); + + LocalDateTime endDateTime = LocalDate.now().atTime(endTime, 0); + + TimeSlot timeSlot = new TimeSlot(startDateTime, endDateTime); + return timeSlot; + } + + public String promptServiceType() { + System.out.println("What type of Service are you doing today?:"); + String serviceType = InputHandler.handleStringInput(); + return serviceType; + } } diff --git a/src/main/java/org/codedifferently/helpers/PatientHandler.java b/src/main/java/org/codedifferently/helpers/PatientHandler.java index 890f78d..02b6f4a 100644 --- a/src/main/java/org/codedifferently/helpers/PatientHandler.java +++ b/src/main/java/org/codedifferently/helpers/PatientHandler.java @@ -1,12 +1,13 @@ package org.codedifferently.helpers; import org.codedifferently.CarClinicSystem; import org.codedifferently.CarPatient; +import org.codedifferently.data.Car; import java.util.UUID; public class PatientHandler { - public void promptNewPatient(CarClinicSystem carClinicSystem) { + public CarPatient promptNewPatient(CarClinicSystem carClinicSystem) { //Prompt user for information. (firstname, lastname, email, phoneNumber) System.out.println("What is your first name?"); @@ -31,6 +32,7 @@ public void promptNewPatient(CarClinicSystem carClinicSystem) { //Add new Car Patient to Car Patient Array List. carClinicSystem.getCarPatients().add(carPatient); + return carPatient; } public void viewAllPatients(CarClinicSystem carClinicSystem) { From 6629f7a37d512e3425eea764db28fc0d20cf6961 Mon Sep 17 00:00:00 2001 From: BennettDeveloper Date: Mon, 23 Feb 2026 01:18:53 -0500 Subject: [PATCH 10/12] fix: Fixed adding appointments and printing appointment with timestamps --- .../org/codedifferently/CarClinicApp.java | 1 - .../org/codedifferently/ShopScheduler.java | 29 ++++++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/codedifferently/CarClinicApp.java b/src/main/java/org/codedifferently/CarClinicApp.java index 76a226e..ebcc2f0 100644 --- a/src/main/java/org/codedifferently/CarClinicApp.java +++ b/src/main/java/org/codedifferently/CarClinicApp.java @@ -125,7 +125,6 @@ void handleAppointmentMenu(CarClinicSystem carClinicSystem) { break; case 2: CarPatient patient = patientHandler.searchForPatient(carClinicSystem); - if(patient == null) { System.out.println("Patient was not found!!!"); //Create new patient if not found. diff --git a/src/main/java/org/codedifferently/ShopScheduler.java b/src/main/java/org/codedifferently/ShopScheduler.java index a469741..d972eff 100644 --- a/src/main/java/org/codedifferently/ShopScheduler.java +++ b/src/main/java/org/codedifferently/ShopScheduler.java @@ -27,6 +27,13 @@ public boolean scheduleAppointment(CarClinicSystem carClinicSystem, CarPatient c // Prevent double booking if (isSlotBooked(carClinicSystem, newAppt.getAppointmentID())) { + System.out.println("Slot is booked! Can't do it!"); + return false; + } + + //Prevent scheduling during off business hours + if(!newAppt.isDuringBusinessHours(newAppt.getTimeSlot())) { + System.out.println("Can't schedule during business hours! Can't do it"); return false; } @@ -39,7 +46,7 @@ public boolean cancelAppointment(CarClinicSystem carClinicSystem, String appoint for(int i = 0; i < carClinicSystem.getCarAppointments().size(); i++) { - if(carClinicSystem.getCarAppointments().get(i).equals(appointmentID)) { + if(carClinicSystem.getCarAppointments().get(i).getAppointmentID().equals(appointmentID)) { carClinicSystem.getCarAppointments().remove(i); return true; } @@ -54,21 +61,16 @@ public void printSchedule(CarClinicSystem carClinicSystem) { for (int i = 0; i < carClinicSystem.getCarAppointments().size(); i++) { - CarAppointment found = null; - - for (CarAppointment appt : carClinicSystem.getCarAppointments()) { - if (1 == i) { - found = appt; - break; - } - } + CarAppointment appointment = carClinicSystem.getCarAppointments().get(i); - if (found == null) { + if (appointment == null) { System.out.println((i + 1) + " - AVAILABLE"); } else { - System.out.println((i + 1) + ") " + found.getTimeSlot().getStart() + - " - " + found.getTimeSlot().getEnd()+ - " (" + found.getServiceType() + ")"); + System.out.println((i + 1) + ". " + "(" + appointment.getAppointmentID() + ") " + + appointment.getCarPatient().getLastName() + ", " + appointment.getCarPatient().getFirstName() + + " (" + appointment.getTimeSlot().getStart() + + " - " + appointment.getTimeSlot().getEnd() + + ") (" + appointment.getServiceType() + ")"); } } } @@ -77,6 +79,7 @@ public TimeSlot promptTimeSlot() { System.out.println("Give me the Start Time:"); int startTime = InputHandler.handleIntegerInput(); + System.out.println("Give me the End Time:"); int endTime = InputHandler.handleIntegerInput(); LocalDateTime startDateTime = LocalDate.now().atTime(startTime, 0); From fea2fc6579417807e9f36cfdda15d10ec03b0170 Mon Sep 17 00:00:00 2001 From: wilfredainsworth Date: Mon, 23 Feb 2026 04:40:43 -0500 Subject: [PATCH 11/12] Added instance counter to CarPatient.java and CarAppointment.java and printing to screen when exiting menu. --- .../org/codedifferently/CarAppointment.java | 25 +++++++++---------- .../org/codedifferently/CarClinicApp.java | 4 ++- .../java/org/codedifferently/CarPatient.java | 10 ++++++-- .../org/codedifferently/ShopScheduler.java | 25 +++++-------------- .../org/codedifferently/data/TimeSlot.java | 2 ++ 5 files changed, 31 insertions(+), 35 deletions(-) diff --git a/src/main/java/org/codedifferently/CarAppointment.java b/src/main/java/org/codedifferently/CarAppointment.java index b8f3c9d..0edfea9 100644 --- a/src/main/java/org/codedifferently/CarAppointment.java +++ b/src/main/java/org/codedifferently/CarAppointment.java @@ -15,11 +15,21 @@ public class CarAppointment { private static final LocalTime OPEN_TIME = LocalTime.of(7,0); private static final LocalTime CLOSE_TIME = LocalTime.of(21,0); private static final LocalTime LAST_APPOINTMENT = LocalTime.of(20,0); - private CarPatient carPatient; private TimeSlot timeSlot; - + private boolean isCompleted; private String serviceType; + private static int instanceCounter; + { + instanceCounter++; + } + public static int getInstanceCounter() { + return instanceCounter; + } + + public boolean isCompleted() { + return isCompleted; + } public boolean isDuringBusinessHours(TimeSlot timeSlot){ LocalTime startTime = timeSlot.getStart().toLocalTime(); @@ -75,15 +85,4 @@ public void setCarPatient(CarPatient carPatient) { this.carPatient = carPatient; } - /*if () - String[] daysOfWeek = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}; - open 7am-9pm daily (14hours/day) - int[] weekdayHours = new int [13]; - ArrayList apptSlots = new ArrayList<>(); - - - public void makeAppt(){ -*/ - - } diff --git a/src/main/java/org/codedifferently/CarClinicApp.java b/src/main/java/org/codedifferently/CarClinicApp.java index ebcc2f0..ada8e53 100644 --- a/src/main/java/org/codedifferently/CarClinicApp.java +++ b/src/main/java/org/codedifferently/CarClinicApp.java @@ -132,7 +132,6 @@ void handleAppointmentMenu(CarClinicSystem carClinicSystem) { } TimeSlot timeSlot = shopScheduler.promptTimeSlot(); String serviceType = shopScheduler.promptServiceType(); - shopScheduler.scheduleAppointment(carClinicSystem, patient, timeSlot, serviceType); break; case 3: @@ -142,6 +141,9 @@ void handleAppointmentMenu(CarClinicSystem carClinicSystem) { break; case 4: System.out.println("Exiting out of Patient Menu!"); + System.out.println("End of day summary report."); + System.out.println("Number of appointments created: " + CarAppointment.getInstanceCounter()); + System.out.println("Number of customers added to system: " + CarPatient.getInstanceCounter()); inAppointmentMenu = false; break; default: diff --git a/src/main/java/org/codedifferently/CarPatient.java b/src/main/java/org/codedifferently/CarPatient.java index 8064f7f..29890b1 100644 --- a/src/main/java/org/codedifferently/CarPatient.java +++ b/src/main/java/org/codedifferently/CarPatient.java @@ -10,8 +10,14 @@ public class CarPatient { private String email; private String phoneNumber; private boolean checkedIn; - //public Car patientCar; + private static int instanceCounter; + { + instanceCounter++; + } + public static int getInstanceCounter() { + return instanceCounter; + } public CarPatient(String patientID, String firstName, String lastName, String email, String phoneNumber) { @@ -23,7 +29,6 @@ public CarPatient(String patientID, String firstName, String lastName, this.checkedIn = false; //this.patientCar = patientCar; } - public String getFirstName() { return firstName; } @@ -33,6 +38,7 @@ public String getLastName() { } public String getEmail() { + return email; } diff --git a/src/main/java/org/codedifferently/ShopScheduler.java b/src/main/java/org/codedifferently/ShopScheduler.java index d972eff..4d7e3af 100644 --- a/src/main/java/org/codedifferently/ShopScheduler.java +++ b/src/main/java/org/codedifferently/ShopScheduler.java @@ -4,9 +4,6 @@ import java.time.LocalDate; import java.time.LocalDateTime; -import java.time.chrono.ChronoLocalDate; -import java.util.ArrayList; -import java.util.UUID; public class ShopScheduler { @@ -42,27 +39,23 @@ public boolean scheduleAppointment(CarClinicSystem carClinicSystem, CarPatient c } // Cancel appointment by timeSlot - public boolean cancelAppointment(CarClinicSystem carClinicSystem, String appointmentID) { - + public void cancelAppointment(CarClinicSystem carClinicSystem, String appointmentID) { for(int i = 0; i < carClinicSystem.getCarAppointments().size(); i++) { - if(carClinicSystem.getCarAppointments().get(i).getAppointmentID().equals(appointmentID)) { carClinicSystem.getCarAppointments().remove(i); - return true; + System.out.println("Appointment canceled."); + }else { + System.out.println("No appointment found."); } } - return false; } // Print full schedule public void printSchedule(CarClinicSystem carClinicSystem) { System.out.println("\n=== CWW Auto Repair Shop Daily Schedule ==="); - for (int i = 0; i < carClinicSystem.getCarAppointments().size(); i++) { - CarAppointment appointment = carClinicSystem.getCarAppointments().get(i); - if (appointment == null) { System.out.println((i + 1) + " - AVAILABLE"); } else { @@ -78,22 +71,16 @@ public void printSchedule(CarClinicSystem carClinicSystem) { public TimeSlot promptTimeSlot() { System.out.println("Give me the Start Time:"); int startTime = InputHandler.handleIntegerInput(); - System.out.println("Give me the End Time:"); int endTime = InputHandler.handleIntegerInput(); - LocalDateTime startDateTime = LocalDate.now().atTime(startTime, 0); - LocalDateTime endDateTime = LocalDate.now().atTime(endTime, 0); - - TimeSlot timeSlot = new TimeSlot(startDateTime, endDateTime); - return timeSlot; + return new TimeSlot(startDateTime, endDateTime); } public String promptServiceType() { System.out.println("What type of Service are you doing today?:"); - String serviceType = InputHandler.handleStringInput(); - return serviceType; + return InputHandler.handleStringInput(); } } diff --git a/src/main/java/org/codedifferently/data/TimeSlot.java b/src/main/java/org/codedifferently/data/TimeSlot.java index a8b16b9..589c7d6 100644 --- a/src/main/java/org/codedifferently/data/TimeSlot.java +++ b/src/main/java/org/codedifferently/data/TimeSlot.java @@ -17,10 +17,12 @@ public LocalDateTime getStart() { } public LocalDateTime getEnd() { + return end; } public Duration getDuration() { + return Duration.between(start, end); } } From 599cd49d439cf07dd88617ff6e32f2ceda83da25 Mon Sep 17 00:00:00 2001 From: whblue261 Date: Mon, 23 Feb 2026 08:37:12 -0500 Subject: [PATCH 12/12] update tier 3 waitlist --- .../org/codedifferently/CarClinicSystem.java | 5 + .../org/codedifferently/ShopScheduler.java | 172 +++++++++++------- .../java/org/codedifferently/Waitlist.java | 37 ++++ .../org/codedifferently/WaitlistEntry.java | 44 +++++ 4 files changed, 195 insertions(+), 63 deletions(-) create mode 100644 src/main/java/org/codedifferently/Waitlist.java create mode 100644 src/main/java/org/codedifferently/WaitlistEntry.java diff --git a/src/main/java/org/codedifferently/CarClinicSystem.java b/src/main/java/org/codedifferently/CarClinicSystem.java index f7ee577..da53b20 100644 --- a/src/main/java/org/codedifferently/CarClinicSystem.java +++ b/src/main/java/org/codedifferently/CarClinicSystem.java @@ -7,6 +7,11 @@ public class CarClinicSystem { private ArrayList carAppointments = new ArrayList<>(); private ArrayList carPatients = new ArrayList<>(); + private final Waitlist waitlist = new Waitlist(); + + public Waitlist getWaitlist() { + return waitlist; + } public ArrayList getCarAppointments() { return carAppointments; } diff --git a/src/main/java/org/codedifferently/ShopScheduler.java b/src/main/java/org/codedifferently/ShopScheduler.java index d972eff..b20b3ec 100644 --- a/src/main/java/org/codedifferently/ShopScheduler.java +++ b/src/main/java/org/codedifferently/ShopScheduler.java @@ -1,99 +1,145 @@ package org.codedifferently; import org.codedifferently.data.TimeSlot; import org.codedifferently.helpers.InputHandler; - +import org.codedifferently.WaitlistEntry; import java.time.LocalDate; import java.time.LocalDateTime; -import java.time.chrono.ChronoLocalDate; -import java.util.ArrayList; -import java.util.UUID; + public class ShopScheduler { - // Check if a slot is already booked - public boolean isSlotBooked(CarClinicSystem carClinicSystem, String appointmentID) { - for (CarAppointment appt : carClinicSystem.getCarAppointments()) { - if (appt.getAppointmentID().equals(appointmentID)) { - return true; // Slot is taken - } + private boolean timeSlotsOverlap(TimeSlot a, TimeSlot b) { + return a.getStart().isBefore(b.getEnd()) && a.getEnd().isAfter(b.getStart()); + } + + public boolean isTimeSlotBooked(CarClinicSystem carClinicSystem, TimeSlot timeSlot) { + for (CarAppointment appt : carClinicSystem.getCarAppointments()) { + if (appt != null && timeSlotsOverlap(appt.getTimeSlot(), timeSlot)) { + return true; } - return false; // Slot is available } + return false; + } - // Schedule an appointment - public boolean scheduleAppointment(CarClinicSystem carClinicSystem, CarPatient customer, TimeSlot timeSlot, String serviceType) { - - CarAppointment newAppt = new CarAppointment(customer, timeSlot, "Oil Change"); - // Prevent double booking - if (isSlotBooked(carClinicSystem, newAppt.getAppointmentID())) { - System.out.println("Slot is booked! Can't do it!"); - return false; - } + public boolean scheduleAppointment(CarClinicSystem carClinicSystem, CarPatient customer, TimeSlot timeSlot, String serviceType) { - //Prevent scheduling during off business hours - if(!newAppt.isDuringBusinessHours(newAppt.getTimeSlot())) { - System.out.println("Can't schedule during business hours! Can't do it"); - return false; - } + // Use the serviceType the user typed (not hardcoded) + CarAppointment newAppt = new CarAppointment(customer, timeSlot, serviceType); - carClinicSystem.getCarAppointments().add(newAppt); - return true; + // Prevent scheduling outside business hours + if (!newAppt.isDuringBusinessHours(newAppt.getTimeSlot())) { + System.out.println("Can't schedule outside business hours!"); + return false; } - // Cancel appointment by timeSlot - public boolean cancelAppointment(CarClinicSystem carClinicSystem, String appointmentID) { + // If slot is already taken, offer waitlist + if (isTimeSlotBooked(carClinicSystem, timeSlot)) { + System.out.println("That time slot is already booked."); - for(int i = 0; i < carClinicSystem.getCarAppointments().size(); i++) { + System.out.println("Would you like to join the waitlist for this time slot?"); + System.out.println("1. Yes"); + System.out.println("2. No"); - if(carClinicSystem.getCarAppointments().get(i).getAppointmentID().equals(appointmentID)) { - carClinicSystem.getCarAppointments().remove(i); - return true; - } + int choice = InputHandler.handleIntegerInput(); + if (choice == 1) { + String entryId = "W" + System.currentTimeMillis(); + WaitlistEntry entry = new WaitlistEntry(entryId, customer, timeSlot, serviceType); + carClinicSystem.getWaitlist().add(entry); + + System.out.println("Added to waitlist! Entry ID: " + entryId); + } else { + System.out.println("Okay, please choose another time slot."); } - return false; + return false; } - // Print full schedule - public void printSchedule(CarClinicSystem carClinicSystem) { - System.out.println("\n=== CWW Auto Repair Shop Daily Schedule ==="); + // Slot is open, schedule it + carClinicSystem.getCarAppointments().add(newAppt); + System.out.println("Appointment scheduled successfully!"); + return true; + } + + // Cancel appointment by timeSlot + public boolean cancelAppointment(CarClinicSystem carClinicSystem, String appointmentID) { + + for (int i = 0; i < carClinicSystem.getCarAppointments().size(); i++) { - for (int i = 0; i < carClinicSystem.getCarAppointments().size(); i++) { + CarAppointment appt = carClinicSystem.getCarAppointments().get(i); - CarAppointment appointment = carClinicSystem.getCarAppointments().get(i); + if (appt.getAppointmentID().equals(appointmentID)) { - if (appointment == null) { - System.out.println((i + 1) + " - AVAILABLE"); - } else { - System.out.println((i + 1) + ". " + "(" + appointment.getAppointmentID() + ") " - + appointment.getCarPatient().getLastName() + ", " + appointment.getCarPatient().getFirstName() - + " (" + appointment.getTimeSlot().getStart() + - " - " + appointment.getTimeSlot().getEnd() + - ") (" + appointment.getServiceType() + ")"); + // Save the freed slot before removing + TimeSlot freedSlot = appt.getTimeSlot(); + + // Remove appointment + carClinicSystem.getCarAppointments().remove(i); + System.out.println("Appointment canceled."); + + // Auto-schedule from waitlist (same slot) + WaitlistEntry next = carClinicSystem.getWaitlist().popNextFor(freedSlot); + + if (next != null) { + CarAppointment waitlistedAppt = new CarAppointment( + next.getPatient(), + freedSlot, + next.getServiceType() + ); + + carClinicSystem.getCarAppointments().add(waitlistedAppt); + + System.out.println("Scheduled from waitlist: " + + next.getPatient().getLastName() + ", " + + next.getPatient().getFirstName()); } + + return true; } } - public TimeSlot promptTimeSlot() { - System.out.println("Give me the Start Time:"); - int startTime = InputHandler.handleIntegerInput(); + return false; + } - System.out.println("Give me the End Time:"); - int endTime = InputHandler.handleIntegerInput(); + // Print full schedule + public void printSchedule(CarClinicSystem carClinicSystem) { + System.out.println("\n=== CWW Auto Repair Shop Daily Schedule ==="); - LocalDateTime startDateTime = LocalDate.now().atTime(startTime, 0); + for (int i = 0; i < carClinicSystem.getCarAppointments().size(); i++) { - LocalDateTime endDateTime = LocalDate.now().atTime(endTime, 0); + CarAppointment appointment = carClinicSystem.getCarAppointments().get(i); - TimeSlot timeSlot = new TimeSlot(startDateTime, endDateTime); - return timeSlot; - } - - public String promptServiceType() { - System.out.println("What type of Service are you doing today?:"); - String serviceType = InputHandler.handleStringInput(); - return serviceType; + if (appointment == null) { + System.out.println((i + 1) + " - AVAILABLE"); + } else { + System.out.println((i + 1) + ". " + "(" + appointment.getAppointmentID() + ") " + + appointment.getCarPatient().getLastName() + ", " + appointment.getCarPatient().getFirstName() + + " (" + appointment.getTimeSlot().getStart() + + " - " + appointment.getTimeSlot().getEnd() + + ") (" + appointment.getServiceType() + ")"); + } } } + public TimeSlot promptTimeSlot() { + System.out.println("Give me the Start Time:"); + int startTime = InputHandler.handleIntegerInput(); + + System.out.println("Give me the End Time:"); + int endTime = InputHandler.handleIntegerInput(); + + LocalDateTime startDateTime = LocalDate.now().atTime(startTime, 0); + + LocalDateTime endDateTime = LocalDate.now().atTime(endTime, 0); + + TimeSlot timeSlot = new TimeSlot(startDateTime, endDateTime); + return timeSlot; + } + + public String promptServiceType() { + System.out.println("What type of Service are you doing today?:"); + String serviceType = InputHandler.handleStringInput(); + return serviceType; + } +} + diff --git a/src/main/java/org/codedifferently/Waitlist.java b/src/main/java/org/codedifferently/Waitlist.java new file mode 100644 index 0000000..7f9ea2c --- /dev/null +++ b/src/main/java/org/codedifferently/Waitlist.java @@ -0,0 +1,37 @@ +package org.codedifferently; + +import org.codedifferently.data.TimeSlot; + + +import java.util.ArrayList; + +public class Waitlist { + + private final ArrayList entries = new ArrayList<>(); + + public void add(WaitlistEntry entry) { + entries.add(entry); + } + + // Returns and removes the first person waiting for this exact TimeSlot + public WaitlistEntry popNextFor(TimeSlot timeSlot) { + for (int i = 0; i < entries.size(); i++) { + if (entries.get(i).getRequestedTimeSlot().equals(timeSlot)) { + return entries.remove(i); + } + } + return null; + } + + public boolean isEmpty() { + return entries.isEmpty(); + } + + public int size() { + return entries.size(); + } + + public ArrayList getAll() { + return entries; + } + } diff --git a/src/main/java/org/codedifferently/WaitlistEntry.java b/src/main/java/org/codedifferently/WaitlistEntry.java new file mode 100644 index 0000000..867943a --- /dev/null +++ b/src/main/java/org/codedifferently/WaitlistEntry.java @@ -0,0 +1,44 @@ +package org.codedifferently; + +import org.codedifferently.CarPatient; +import org.codedifferently.data.TimeSlot; + + +public class WaitlistEntry { + private final String entryId; + private final CarPatient patient; + private final TimeSlot requestedTimeSlot; + private final String serviceType; + + public WaitlistEntry(String entryId, CarPatient patient, TimeSlot requestedTimeSlot, String serviceType) { + this.entryId = entryId; + this.patient = patient; + this.requestedTimeSlot = requestedTimeSlot; + this.serviceType = serviceType; + } + + public String getEntryId() { + return entryId; + } + + public CarPatient getPatient() { + return patient; + } + + public TimeSlot getRequestedTimeSlot() { + return requestedTimeSlot; + } + + public String getServiceType() { + return serviceType; + } + + @Override + public String toString() { + return "Entry ID: " + entryId + + " | Patient: " + patient.getLastName() + ", " + patient.getFirstName() + + " | TimeSlot: " + requestedTimeSlot + + " | Service: " + serviceType; + } +} +