From 47687796d468e880556f55db28b31cc76e1052a2 Mon Sep 17 00:00:00 2001 From: Jayden Andrews Date: Thu, 19 Feb 2026 16:45:03 -0500 Subject: [PATCH 01/17] Implemented Patient class -Bobby --- .idea/misc.xml | 2 +- .../org/codedifferently/AmaniAppointment.java | 32 ++++++++++++++ .../org/codedifferently/BobbyPatient.java | 44 +++++++++++++++++++ .../org/codedifferently/JaydenClinicApp.java | 5 +++ .../codedifferently/JaydenClinicSystem.java | 23 ++++++++++ 5 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/codedifferently/AmaniAppointment.java create mode 100644 src/main/java/org/codedifferently/BobbyPatient.java create mode 100644 src/main/java/org/codedifferently/JaydenClinicApp.java create mode 100644 src/main/java/org/codedifferently/JaydenClinicSystem.java diff --git a/.idea/misc.xml b/.idea/misc.xml index fdc35ea..0c04b52 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -8,7 +8,7 @@ - + \ No newline at end of file diff --git a/src/main/java/org/codedifferently/AmaniAppointment.java b/src/main/java/org/codedifferently/AmaniAppointment.java new file mode 100644 index 0000000..f02704c --- /dev/null +++ b/src/main/java/org/codedifferently/AmaniAppointment.java @@ -0,0 +1,32 @@ +package org.codedifferently; +import java.util.ArrayList; + +public class AmaniAppointment { + private ArrayList appointments = new ArrayList(); + private String name; + private String haircut; + + // Constructor + public AmaniAppointment(String name, String haircut) { + this.name = name; + this.haircut = haircut; + } + + public void scheduleAppointment(BobbyPatient customer) { + // Make an appointment using constructor + // Add that appt to appointments variable + } + + public void cancelAppointment(BobbyPatient customer) { + // Check the appointments array + // If found, remove it from the appointments array + } + + public void checkIn(BobbyPatient customer) { + // Check the appointments array and confirm the customer's appointment + } + + public void viewSchedule() { + System.out.println(appointments); + } +} diff --git a/src/main/java/org/codedifferently/BobbyPatient.java b/src/main/java/org/codedifferently/BobbyPatient.java new file mode 100644 index 0000000..25f3a9b --- /dev/null +++ b/src/main/java/org/codedifferently/BobbyPatient.java @@ -0,0 +1,44 @@ +package org.codedifferently; +import java.util.ArrayList; +import java.util.Random; + +public class BobbyPatient { + private String name; + private String phoneNumber; + private final String patientId; + private String haircut; + + // Constructor + public BobbyPatient(String name, String phoneNumber) { + this.name = name; + this.phoneNumber = phoneNumber; + this.patientId = generatePatientId(new Random()); + } + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPhoneNumber() { + return phoneNumber; + } + + public void setPhoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + public String getPatientId() { + return patientId; + } + + public String generatePatientId(Random random) { + return name.substring(0, 3).toUpperCase() + random.nextInt(10000, 100000); + } + + +} diff --git a/src/main/java/org/codedifferently/JaydenClinicApp.java b/src/main/java/org/codedifferently/JaydenClinicApp.java new file mode 100644 index 0000000..80da3f3 --- /dev/null +++ b/src/main/java/org/codedifferently/JaydenClinicApp.java @@ -0,0 +1,5 @@ +package org.codedifferently; +import java.util.ArrayList; + +public class JaydenClinicApp { +} diff --git a/src/main/java/org/codedifferently/JaydenClinicSystem.java b/src/main/java/org/codedifferently/JaydenClinicSystem.java new file mode 100644 index 0000000..b1d1be0 --- /dev/null +++ b/src/main/java/org/codedifferently/JaydenClinicSystem.java @@ -0,0 +1,23 @@ +package org.codedifferently; +import java.util.ArrayList; + +public class JaydenClinicSystem { + private ArrayList customers = new ArrayList(); + + public void displayMenu() { + + } + + public void addCustomer(BobbyPatient customer) { + this.customers.add(customer); + } + + public ArrayList getCustomers() { + return customers; + } + + public void findCustomer(BobbyPatient customer) { + // Code goes here + } + +} From 549c04f6ec25e1f0c5016137d676ae7e4de36136 Mon Sep 17 00:00:00 2001 From: Jayden Andrews Date: Fri, 20 Feb 2026 12:25:05 -0500 Subject: [PATCH 02/17] Implemented prototype of clinic system. --- .../org/codedifferently/BobbyPatient.java | 1 - .../codedifferently/JaydenClinicSystem.java | 81 +++++++++++++++++-- 2 files changed, 76 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/codedifferently/BobbyPatient.java b/src/main/java/org/codedifferently/BobbyPatient.java index 25f3a9b..c47f2ac 100644 --- a/src/main/java/org/codedifferently/BobbyPatient.java +++ b/src/main/java/org/codedifferently/BobbyPatient.java @@ -1,5 +1,4 @@ package org.codedifferently; -import java.util.ArrayList; import java.util.Random; public class BobbyPatient { diff --git a/src/main/java/org/codedifferently/JaydenClinicSystem.java b/src/main/java/org/codedifferently/JaydenClinicSystem.java index b1d1be0..e2a4ebe 100644 --- a/src/main/java/org/codedifferently/JaydenClinicSystem.java +++ b/src/main/java/org/codedifferently/JaydenClinicSystem.java @@ -1,22 +1,93 @@ package org.codedifferently; import java.util.ArrayList; +import java.util.Scanner; +import java.util.regex.*; public class JaydenClinicSystem { - private ArrayList customers = new ArrayList(); + private static ArrayList customers = new ArrayList<>(); - public void displayMenu() { + public void displayOptions(Scanner sc) { + System.out.println("Welcome! What would you like to do today? (Enter a number)"); + int input; + do { + // Prints the menu. + System.out.println("Barber Shop Management System"); + System.out.println("1. Add a new customer."); + System.out.println("2. View all customers."); + System.out.println("3. Check in a customer."); + System.out.println("4. Search for a customer."); + System.out.print("Selection: "); + + // Validates the input. + if (sc.hasNextInt()) { + input = sc.nextInt(); + } else { + input = -1; + } + sc.nextLine(); + + + switch (input) { + case 1: + System.out.print("Enter your name: "); + String name = sc.nextLine(); + + // The regex that will be used to match the phone number input + String regex = "^\\+?1?\\D*?(\\d{3})\\D*?(\\d{3})\\D*?(\\d{4})$"; + // Turns the regex into a pattern object. + Pattern pattern = Pattern.compile(regex); + + String phoneNumber; + + while (true) { + // Prompts the user to enter their phone number. + System.out.print("Enter your phone number (XXX-XXX-XXXX): "); + phoneNumber = sc.nextLine(); + + // Checks the phone number to see if it matches the pattern. + Matcher matcher = pattern.matcher(phoneNumber); + + // If the phone number matches the expected structure + if (matcher.matches()) { + + // Reformat into XXX-XXX-XXXX + phoneNumber = matcher.group(1) + "-" + matcher.group(2) + "-" + matcher.group(3); + // Exit loop + break; + } else { + System.out.println("\nInvalid phone number. Please try again.\n"); + } + } + addCustomer(new BobbyPatient(name, phoneNumber)); + case 2: + System.out.println(getCustomers()); + break; + case 3: + // AmaniAppointment.checkIn(); + break; + case 4: + System.out.println("Enter customer id: "); + String customerId = sc.nextLine(); + findCustomer(customerId); + break; + case 5: + System.out.println("Exiting system."); + default: + System.out.println("\nPlease select a valid option.\n"); + } + } while (input != 4); } public void addCustomer(BobbyPatient customer) { - this.customers.add(customer); + customers.add(customer); } - public ArrayList getCustomers() { + public static ArrayList getCustomers() { return customers; } - public void findCustomer(BobbyPatient customer) { + public void findCustomer(String customerId) { // Code goes here } From 831fe173011c8b8cb66683e3cca96af0e48effe2 Mon Sep 17 00:00:00 2001 From: Jayden Andrews Date: Fri, 20 Feb 2026 15:11:42 -0500 Subject: [PATCH 03/17] Implemented customer search, and wrote formatPhoneNumber method --- .../org/codedifferently/AmaniAppointment.java | 6 +- .../org/codedifferently/BobbyPatient.java | 6 +- .../org/codedifferently/JaydenClinicApp.java | 5 +- .../codedifferently/JaydenClinicSystem.java | 91 +++++++++++-------- 4 files changed, 65 insertions(+), 43 deletions(-) diff --git a/src/main/java/org/codedifferently/AmaniAppointment.java b/src/main/java/org/codedifferently/AmaniAppointment.java index f02704c..24d4b5f 100644 --- a/src/main/java/org/codedifferently/AmaniAppointment.java +++ b/src/main/java/org/codedifferently/AmaniAppointment.java @@ -2,7 +2,7 @@ import java.util.ArrayList; public class AmaniAppointment { - private ArrayList appointments = new ArrayList(); + private ArrayList appointments = new ArrayList<>(); private String name; private String haircut; @@ -12,6 +12,10 @@ public AmaniAppointment(String name, String haircut) { this.haircut = haircut; } + public static void appointmentMenu() { + // Code goes here + } + public void scheduleAppointment(BobbyPatient customer) { // Make an appointment using constructor // Add that appt to appointments variable diff --git a/src/main/java/org/codedifferently/BobbyPatient.java b/src/main/java/org/codedifferently/BobbyPatient.java index c47f2ac..1a45b43 100644 --- a/src/main/java/org/codedifferently/BobbyPatient.java +++ b/src/main/java/org/codedifferently/BobbyPatient.java @@ -14,7 +14,6 @@ public BobbyPatient(String name, String phoneNumber) { this.patientId = generatePatientId(new Random()); } - public String getName() { return name; } @@ -39,5 +38,10 @@ public String generatePatientId(Random random) { return name.substring(0, 3).toUpperCase() + random.nextInt(10000, 100000); } + @Override + public String toString() { + return "\n(Name: " + name + ", Phone: " + phoneNumber + ", PatientId: " + patientId + ")"; + } + } diff --git a/src/main/java/org/codedifferently/JaydenClinicApp.java b/src/main/java/org/codedifferently/JaydenClinicApp.java index 80da3f3..84f5069 100644 --- a/src/main/java/org/codedifferently/JaydenClinicApp.java +++ b/src/main/java/org/codedifferently/JaydenClinicApp.java @@ -1,5 +1,8 @@ package org.codedifferently; -import java.util.ArrayList; +import java.util.Scanner; public class JaydenClinicApp { + public static void main(String[] args) { + JaydenClinicSystem.displayOptions(new Scanner(System.in)); + } } diff --git a/src/main/java/org/codedifferently/JaydenClinicSystem.java b/src/main/java/org/codedifferently/JaydenClinicSystem.java index e2a4ebe..e705c04 100644 --- a/src/main/java/org/codedifferently/JaydenClinicSystem.java +++ b/src/main/java/org/codedifferently/JaydenClinicSystem.java @@ -6,8 +6,8 @@ public class JaydenClinicSystem { private static ArrayList customers = new ArrayList<>(); - public void displayOptions(Scanner sc) { - System.out.println("Welcome! What would you like to do today? (Enter a number)"); + public static void displayOptions(Scanner sc) { + System.out.println("Welcome! What would you like to do today? (Enter a number)\n"); int input; do { @@ -15,8 +15,9 @@ public void displayOptions(Scanner sc) { System.out.println("Barber Shop Management System"); System.out.println("1. Add a new customer."); System.out.println("2. View all customers."); - System.out.println("3. Check in a customer."); + System.out.println("3. Manage appointment."); System.out.println("4. Search for a customer."); + System.out.println("5. Quit"); System.out.print("Selection: "); // Validates the input. @@ -27,59 +28,46 @@ public void displayOptions(Scanner sc) { } sc.nextLine(); + // The regex that will be used to match the phone number input + String regex = "^\\+?1?\\D*?(\\d{3})\\D*?(\\d{3})\\D*?(\\d{4})$"; + // Turns the regex into a pattern object. + Pattern pattern = Pattern.compile(regex); + String phoneNumber; switch (input) { case 1: - System.out.print("Enter your name: "); + System.out.print("\nEnter your name: "); String name = sc.nextLine(); - - // The regex that will be used to match the phone number input - String regex = "^\\+?1?\\D*?(\\d{3})\\D*?(\\d{3})\\D*?(\\d{4})$"; - // Turns the regex into a pattern object. - Pattern pattern = Pattern.compile(regex); - - String phoneNumber; - - while (true) { - // Prompts the user to enter their phone number. - System.out.print("Enter your phone number (XXX-XXX-XXXX): "); - phoneNumber = sc.nextLine(); - - // Checks the phone number to see if it matches the pattern. - Matcher matcher = pattern.matcher(phoneNumber); - - // If the phone number matches the expected structure - if (matcher.matches()) { - - // Reformat into XXX-XXX-XXXX - phoneNumber = matcher.group(1) + "-" + matcher.group(2) + "-" + matcher.group(3); - // Exit loop - break; - } else { - System.out.println("\nInvalid phone number. Please try again.\n"); - } - } + phoneNumber = formatPhoneNumber(pattern, sc); addCustomer(new BobbyPatient(name, phoneNumber)); + break; case 2: System.out.println(getCustomers()); break; case 3: - // AmaniAppointment.checkIn(); + AmaniAppointment.appointmentMenu(); break; case 4: - System.out.println("Enter customer id: "); - String customerId = sc.nextLine(); - findCustomer(customerId); + phoneNumber = formatPhoneNumber(pattern, sc); + BobbyPatient customer = searchCustomer(phoneNumber); + + if (customer != null) { + System.out.print("Customer found:"); + System.out.println(customer + "\n"); + } else { + System.out.println("Customer not found."); + } break; case 5: - System.out.println("Exiting system."); + System.out.println("\nExiting system..."); + break; default: System.out.println("\nPlease select a valid option.\n"); } - } while (input != 4); + } while (input != 5); } - public void addCustomer(BobbyPatient customer) { + public static void addCustomer(BobbyPatient customer) { customers.add(customer); } @@ -87,8 +75,31 @@ public static ArrayList getCustomers() { return customers; } - public void findCustomer(String customerId) { - // Code goes here + public static BobbyPatient searchCustomer(String phoneNumber) { + for (BobbyPatient customer : customers) { + if (customer.getPhoneNumber().equals(phoneNumber)) { + return customer; + } + } + return null; } + public static String formatPhoneNumber(Pattern pattern, Scanner sc) { + while (true) { + // Prompts the user to enter their phone number. + System.out.print("Enter your phone number: "); + String phoneNumber = sc.nextLine(); + + // Checks the phone number to see if it matches the pattern. + Matcher matcher = pattern.matcher(phoneNumber); + + // If the phone number matches the expected structure + if (matcher.matches()) { + // Reformat into XXX-XXX-XXXX + return (matcher.group(1) + "-" + matcher.group(2) + "-" + matcher.group(3)); + } else { + System.out.println("\nInvalid phone number. Please try again.\n"); + } + } + } } From 0eed267cc41e7d9536f996d20c1f6934ee8b7f36 Mon Sep 17 00:00:00 2001 From: aadrummond261 Date: Sat, 21 Feb 2026 15:41:05 -0500 Subject: [PATCH 04/17] Made a schedule with time slots for appointments for barber shop --- .../org/codedifferently/AmaniAppointment.java | 166 ++++++++++++++++-- 1 file changed, 154 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/codedifferently/AmaniAppointment.java b/src/main/java/org/codedifferently/AmaniAppointment.java index 24d4b5f..d195e6d 100644 --- a/src/main/java/org/codedifferently/AmaniAppointment.java +++ b/src/main/java/org/codedifferently/AmaniAppointment.java @@ -1,36 +1,178 @@ package org.codedifferently; import java.util.ArrayList; +import java.util.Scanner; public class AmaniAppointment { - private ArrayList appointments = new ArrayList<>(); + private static final String[] TIME_SLOTS = {"9:00 AM", "9:30 AM", "10:00 AM", "10:30 AM", + "11:00 AM", "11:30 AM", "12:00 PM", "12:30 PM", "1:00 PM", "1:30 PM", "2:00 PM", "2:30 PM", + "3:00 PM", "3:30 PM", "4:00 PM", "4:30 PM", "5:00 PM"}; + private static final ArrayList appointments = new ArrayList<>(); private String name; private String haircut; + private String timeSlot; + private String patientId; // Constructor - public AmaniAppointment(String name, String haircut) { - this.name = name; + public AmaniAppointment(BobbyPatient customer, String haircut, String timeSlot) { + this.name = customer.getName(); this.haircut = haircut; + this.timeSlot = timeSlot; + this.patientId = customer.getPatientId(); } - public static void appointmentMenu() { - // Code goes here + public static void appointmentMenu(BobbyPatient customer) { + Scanner scanner = new Scanner(System.in); + appointmentMenu(customer, scanner); } - public void scheduleAppointment(BobbyPatient customer) { - // Make an appointment using constructor - // Add that appt to appointments variable + + public static void appointmentMenu(BobbyPatient customer, Scanner scanner) { + boolean running = true; + + while (running) { + System.out.println("\n=== Appointment Menu ==="); + System.out.println("1) Schedule Appointment"); + System.out.println("2) Cancel Appointment"); + System.out.println("3) Check In"); + System.out.println("4) View Schedule"); + System.out.println("0) Exit"); + System.out.println("Choose: "); + + int choice = readInt(scanner); + + AmaniAppointment temp = new AmaniAppointment(customer, "N/A", "N/A"); + switch (choice) { + case 1 -> temp.scheduleAppointment(customer, scanner); + break; + case 2 -> temp.cancelAppointment(customer); + break; + case 3 -> temp.checkIn(customer); + break; + case 4 -> temp.viewSchedule(); + break; + case 0 -> running = false; + break; + default -> System.out.println("Invalid option."); + } + } + + + } + + public void scheduleAppointment(BobbyPatient customer, Scanner scanner) { + System.out.println("\n--- Schedule Appointment ---"); + + int slotIndex = promptForSlot(scanner); + String slot = TIME_SLOTS[slotIndex]; + + if (findAppointmentBySlot(slot) != null) { + System.out.println("That time slot is already booked. Pick another."); + return; + } + + AmaniAppointment existing = findAppointmentByPatient(customer.getPatientId()); + if (existing != null) { + System.out.println("You already have an appointment at " + existing.timeSlot + "."); + System.out.println("Cancel it first if you want to reschedule."); + return; + } + + System.out.println("Enter haircut/service (ex: Fade, Trim, Lineup): "); + String haircutInput = scanner.nextLine().trim(); + while (haircutInput.isEmpty()) { + System.out.println("Service cannot be empty. Enter haircut/service: "); + haircutInput = scanner.nextLine().trim(); + } + + appointments.add(new AmaniAppointment(customer, haircutInput, slot)); + System.out.println("Booked! " + customer.getName() + " at " + slot + " for " + haircutInput + "."); + } public void cancelAppointment(BobbyPatient customer) { - // Check the appointments array - // If found, remove it from the appointments array + System.out.println("\n--- Cancel Appointment ---"); + + AmaniAppointment appt = findAppointmentByPatient(customer.getPatientId()); + if (appt == null) { + System.out.println("No appointment found for " + customer.getName() + "."); + return; + } + appointments.remove(appt); + System.out.println("Canceled appointment at " + appt.timeSlot + " for " + customer.getName() + "."); + } public void checkIn(BobbyPatient customer) { - // Check the appointments array and confirm the customer's appointment + System.out.println("\n--- Check In ---"); + + AmaniAppointment appt = findAppointmentByPatient(customer.getPatientId()); + if (appt == null) { + System.out.println("No appointment found for " + customer.getName() + "."); + return; + } + + System.out.println("Checked in: " + appt.name + " | " + appt.timeSlot + " | " + appt.haircut); } public void viewSchedule() { - System.out.println(appointments); + System.out.println("\n--- Full Schedule ---"); + + for (String slot : TIME_SLOTS) { + AmaniAppointment appt = findAppointmentBySlot(slot); + if (appt == null) { + System.out.println(slot + " -> Available"); + } else { + System.out.println(slot + " -> BOOKED " + appt.name + " (" + appt.haircut + ")"); + } + } + } + + private int promptForSlot(Scanner scanner) { + System.out.println("Available time slots:"); + for (int i = 0; i < TIME_SLOTS.length; i++) { + System.out.println((i + 1) + ")" + TIME_SLOTS[i]); + } + + System.out.println("Pick a slot number (1-" + TIME_SLOTS.length + ": "); + int slotNum = readInt(scanner); + while (slotNum < 1 || slotNum > TIME_SLOTS.length) { + System.out.println("Invalid slot. Pick 1-" + TIME_SLOTS.length + ": "); + slotNum = readInt(scanner); + } + return slotNum -1; + } + + private static int readInt(Scanner scanner) { + while (!scanner.hasNextInt()) { + scanner.nextLine(); + System.out.println("Enter a number: "); + } + int val = scanner.nextInt(); + scanner.nextLine(); + return val; + } + + private static AmaniAppointment findAppointmentBySlot(String slot) { + for (AmaniAppointment appt : appointments) { + if (appt.timeSlot.equals(slot)) { + return appt; + } + } + return null; + } + + private static AmaniAppointment findAppointmentByPatient(String patientId) { + for (AmaniAppointment appt : appointments) { + if (appt.patientId.equals(patientId)) { + return appt; + } + } + return null; + } + + @Override + public String toString() { + return "Appointment{name='" + name + "', patientId='" + patientId + "', timeSlot='" + timeSlot + "', haicut='" + + haircut + "'}"; } } From 74ad5c0432e06b50eb50066d1f6076c89150918b Mon Sep 17 00:00:00 2001 From: aadrummond261 Date: Sat, 21 Feb 2026 17:24:38 -0500 Subject: [PATCH 05/17] Debugged and updated AmaniAppointmentMenu --- ...intment.java => AmaniAppointmentMenu.java} | 37 ++++++++----------- 1 file changed, 16 insertions(+), 21 deletions(-) rename src/main/java/org/codedifferently/{AmaniAppointment.java => AmaniAppointmentMenu.java} (80%) diff --git a/src/main/java/org/codedifferently/AmaniAppointment.java b/src/main/java/org/codedifferently/AmaniAppointmentMenu.java similarity index 80% rename from src/main/java/org/codedifferently/AmaniAppointment.java rename to src/main/java/org/codedifferently/AmaniAppointmentMenu.java index d195e6d..86ae5e4 100644 --- a/src/main/java/org/codedifferently/AmaniAppointment.java +++ b/src/main/java/org/codedifferently/AmaniAppointmentMenu.java @@ -2,31 +2,31 @@ import java.util.ArrayList; import java.util.Scanner; -public class AmaniAppointment { +public class AmaniAppointmentMenu { private static final String[] TIME_SLOTS = {"9:00 AM", "9:30 AM", "10:00 AM", "10:30 AM", "11:00 AM", "11:30 AM", "12:00 PM", "12:30 PM", "1:00 PM", "1:30 PM", "2:00 PM", "2:30 PM", "3:00 PM", "3:30 PM", "4:00 PM", "4:30 PM", "5:00 PM"}; - private static final ArrayList appointments = new ArrayList<>(); + private static final ArrayList appointments = new ArrayList<>(); private String name; private String haircut; private String timeSlot; private String patientId; // Constructor - public AmaniAppointment(BobbyPatient customer, String haircut, String timeSlot) { + public AmaniAppointmentMenu(BobbyPatient customer, String haircut, String timeSlot) { this.name = customer.getName(); this.haircut = haircut; this.timeSlot = timeSlot; this.patientId = customer.getPatientId(); } - public static void appointmentMenu(BobbyPatient customer) { + public static void AmaniAppointmentMenu(BobbyPatient customer) { Scanner scanner = new Scanner(System.in); - appointmentMenu(customer, scanner); + AmaniAppointmentMenu(customer, scanner); } - public static void appointmentMenu(BobbyPatient customer, Scanner scanner) { + public static void AmaniAppointmentMenu(BobbyPatient customer, Scanner scanner) { boolean running = true; while (running) { @@ -40,18 +40,13 @@ public static void appointmentMenu(BobbyPatient customer, Scanner scanner) { int choice = readInt(scanner); - AmaniAppointment temp = new AmaniAppointment(customer, "N/A", "N/A"); + AmaniAppointmentMenu temp = new AmaniAppointmentMenu(customer, "N/A", "N/A"); switch (choice) { case 1 -> temp.scheduleAppointment(customer, scanner); - break; case 2 -> temp.cancelAppointment(customer); - break; case 3 -> temp.checkIn(customer); - break; case 4 -> temp.viewSchedule(); - break; case 0 -> running = false; - break; default -> System.out.println("Invalid option."); } } @@ -70,7 +65,7 @@ public void scheduleAppointment(BobbyPatient customer, Scanner scanner) { return; } - AmaniAppointment existing = findAppointmentByPatient(customer.getPatientId()); + AmaniAppointmentMenu existing = findAppointmentByPatient(customer.getPatientId()); if (existing != null) { System.out.println("You already have an appointment at " + existing.timeSlot + "."); System.out.println("Cancel it first if you want to reschedule."); @@ -84,7 +79,7 @@ public void scheduleAppointment(BobbyPatient customer, Scanner scanner) { haircutInput = scanner.nextLine().trim(); } - appointments.add(new AmaniAppointment(customer, haircutInput, slot)); + appointments.add(new AmaniAppointmentMenu(customer, haircutInput, slot)); System.out.println("Booked! " + customer.getName() + " at " + slot + " for " + haircutInput + "."); } @@ -92,7 +87,7 @@ public void scheduleAppointment(BobbyPatient customer, Scanner scanner) { public void cancelAppointment(BobbyPatient customer) { System.out.println("\n--- Cancel Appointment ---"); - AmaniAppointment appt = findAppointmentByPatient(customer.getPatientId()); + AmaniAppointmentMenu appt = findAppointmentByPatient(customer.getPatientId()); if (appt == null) { System.out.println("No appointment found for " + customer.getName() + "."); return; @@ -105,7 +100,7 @@ public void cancelAppointment(BobbyPatient customer) { public void checkIn(BobbyPatient customer) { System.out.println("\n--- Check In ---"); - AmaniAppointment appt = findAppointmentByPatient(customer.getPatientId()); + AmaniAppointmentMenu appt = findAppointmentByPatient(customer.getPatientId()); if (appt == null) { System.out.println("No appointment found for " + customer.getName() + "."); return; @@ -118,7 +113,7 @@ public void viewSchedule() { System.out.println("\n--- Full Schedule ---"); for (String slot : TIME_SLOTS) { - AmaniAppointment appt = findAppointmentBySlot(slot); + AmaniAppointmentMenu appt = findAppointmentBySlot(slot); if (appt == null) { System.out.println(slot + " -> Available"); } else { @@ -152,8 +147,8 @@ private static int readInt(Scanner scanner) { return val; } - private static AmaniAppointment findAppointmentBySlot(String slot) { - for (AmaniAppointment appt : appointments) { + private static AmaniAppointmentMenu findAppointmentBySlot(String slot) { + for (AmaniAppointmentMenu appt : appointments) { if (appt.timeSlot.equals(slot)) { return appt; } @@ -161,8 +156,8 @@ private static AmaniAppointment findAppointmentBySlot(String slot) { return null; } - private static AmaniAppointment findAppointmentByPatient(String patientId) { - for (AmaniAppointment appt : appointments) { + private static AmaniAppointmentMenu findAppointmentByPatient(String patientId) { + for (AmaniAppointmentMenu appt : appointments) { if (appt.patientId.equals(patientId)) { return appt; } From 32edb3826061e86059908565ca0966518ea9f6f7 Mon Sep 17 00:00:00 2001 From: Jayden Andrews Date: Sat, 21 Feb 2026 19:28:59 -0500 Subject: [PATCH 06/17] Implemented summary report & completion tracking --- .../codedifferently/AmaniAppointmentMenu.java | 44 ++++++++++++++----- .../codedifferently/JaydenClinicSystem.java | 41 ++++++++++++----- 2 files changed, 63 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/codedifferently/AmaniAppointmentMenu.java b/src/main/java/org/codedifferently/AmaniAppointmentMenu.java index 86ae5e4..5fd5c00 100644 --- a/src/main/java/org/codedifferently/AmaniAppointmentMenu.java +++ b/src/main/java/org/codedifferently/AmaniAppointmentMenu.java @@ -11,6 +11,7 @@ public class AmaniAppointmentMenu { private String haircut; private String timeSlot; private String patientId; + private boolean checkedIn; // Constructor public AmaniAppointmentMenu(BobbyPatient customer, String haircut, String timeSlot) { @@ -18,15 +19,10 @@ public AmaniAppointmentMenu(BobbyPatient customer, String haircut, String timeSl this.haircut = haircut; this.timeSlot = timeSlot; this.patientId = customer.getPatientId(); + this.checkedIn = false; } - public static void AmaniAppointmentMenu(BobbyPatient customer) { - Scanner scanner = new Scanner(System.in); - AmaniAppointmentMenu(customer, scanner); - } - - - public static void AmaniAppointmentMenu(BobbyPatient customer, Scanner scanner) { + public static ArrayList appointmentMenu(BobbyPatient customer, Scanner scanner) { boolean running = true; while (running) { @@ -51,7 +47,7 @@ public static void AmaniAppointmentMenu(BobbyPatient customer, Scanner scanner) } } - + return appointments; } public void scheduleAppointment(BobbyPatient customer, Scanner scanner) { @@ -105,7 +101,7 @@ public void checkIn(BobbyPatient customer) { System.out.println("No appointment found for " + customer.getName() + "."); return; } - + appt.setCheckedIn(true); System.out.println("Checked in: " + appt.name + " | " + appt.timeSlot + " | " + appt.haircut); } @@ -117,7 +113,11 @@ public void viewSchedule() { if (appt == null) { System.out.println(slot + " -> Available"); } else { - System.out.println(slot + " -> BOOKED " + appt.name + " (" + appt.haircut + ")"); + if (appt.checkedIn) { + System.out.println(slot + " -> BOOKED " + appt.name + " (" + appt.haircut + ") Checked In?: Yes" ); + } else { + System.out.println(slot + " -> BOOKED " + appt.name + " (" + appt.haircut + ") Checked In?: No" ); + } } } } @@ -170,4 +170,28 @@ public String toString() { return "Appointment{name='" + name + "', patientId='" + patientId + "', timeSlot='" + timeSlot + "', haicut='" + haircut + "'}"; } + + public boolean getCheckedIn() { + return this.checkedIn; + } + + public void setCheckedIn(boolean checkedIn) { + this.checkedIn = checkedIn; + } + + public String getName() { + return this.name; + } + + public String getPatientId() { + return this.patientId; + } + + public String getHaircut() { + return this.haircut; + } + + public String getTimeSlot() { + return this.timeSlot; + } } diff --git a/src/main/java/org/codedifferently/JaydenClinicSystem.java b/src/main/java/org/codedifferently/JaydenClinicSystem.java index e705c04..f292537 100644 --- a/src/main/java/org/codedifferently/JaydenClinicSystem.java +++ b/src/main/java/org/codedifferently/JaydenClinicSystem.java @@ -9,16 +9,17 @@ public class JaydenClinicSystem { public static void displayOptions(Scanner sc) { System.out.println("Welcome! What would you like to do today? (Enter a number)\n"); int input; + ArrayList appointments = null; do { // Prints the menu. System.out.println("Barber Shop Management System"); - System.out.println("1. Add a new customer."); - System.out.println("2. View all customers."); - System.out.println("3. Manage appointment."); - System.out.println("4. Search for a customer."); - System.out.println("5. Quit"); - System.out.print("Selection: "); + System.out.println("1) Add a new customer."); + System.out.println("2) View all customers."); + System.out.println("3) Manage appointment for a customer."); + System.out.println("4) Search for a customer."); + System.out.println("0) Quit"); + System.out.print("Choose: "); // Validates the input. if (sc.hasNextInt()) { @@ -45,26 +46,42 @@ public static void displayOptions(Scanner sc) { System.out.println(getCustomers()); break; case 3: - AmaniAppointment.appointmentMenu(); + phoneNumber = formatPhoneNumber(pattern, sc); + BobbyPatient customer = searchCustomer(phoneNumber); + if (customer != null) { + appointments = AmaniAppointmentMenu.appointmentMenu(customer, sc); + } else { + System.out.println("Customer not in database. Please add them first.\n"); + } break; case 4: phoneNumber = formatPhoneNumber(pattern, sc); - BobbyPatient customer = searchCustomer(phoneNumber); + BobbyPatient customer2 = searchCustomer(phoneNumber); - if (customer != null) { + if (customer2 != null) { System.out.print("Customer found:"); - System.out.println(customer + "\n"); + System.out.println(customer2 + "\n"); } else { System.out.println("Customer not found."); } break; - case 5: + case 0: + System.out.println("\nRecords"); + if (appointments != null) { + for (AmaniAppointmentMenu appt: appointments) { + if (appt.getCheckedIn()) { + System.out.println(appt.getTimeSlot() + " -> [Name: " + appt.getName() + ", " + + "Patient Id: " + appt.getPatientId() + ", " + + "Haircut: " + appt.getHaircut() + "]"); + } + } + } System.out.println("\nExiting system..."); break; default: System.out.println("\nPlease select a valid option.\n"); } - } while (input != 5); + } while (input != 0); } public static void addCustomer(BobbyPatient customer) { From b41b54058a35a768abc56c4fa26035cdaba2186e Mon Sep 17 00:00:00 2001 From: Jayden Andrews Date: Sun, 22 Feb 2026 13:11:48 -0500 Subject: [PATCH 07/17] Added comments for the appointment menu and clinic app --- .../codedifferently/AmaniAppointmentMenu.java | 91 ++++++++++++++++--- .../org/codedifferently/BobbyPatient.java | 13 +-- .../org/codedifferently/JaydenClinicApp.java | 1 + 3 files changed, 80 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/codedifferently/AmaniAppointmentMenu.java b/src/main/java/org/codedifferently/AmaniAppointmentMenu.java index 5fd5c00..f999365 100644 --- a/src/main/java/org/codedifferently/AmaniAppointmentMenu.java +++ b/src/main/java/org/codedifferently/AmaniAppointmentMenu.java @@ -1,19 +1,39 @@ package org.codedifferently; + import java.util.ArrayList; import java.util.Scanner; +// Defines the AmaniAppointmentMenu class that manages appointment scheduling and tracking. public class AmaniAppointmentMenu { - private static final String[] TIME_SLOTS = {"9:00 AM", "9:30 AM", "10:00 AM", "10:30 AM", - "11:00 AM", "11:30 AM", "12:00 PM", "12:30 PM", "1:00 PM", "1:30 PM", "2:00 PM", "2:30 PM", - "3:00 PM", "3:30 PM", "4:00 PM", "4:30 PM", "5:00 PM"}; + + // Stores all available appointment time slots for the day. + private static final String[] TIME_SLOTS = { + "9:00 AM", "9:30 AM", "10:00 AM", "10:30 AM", + "11:00 AM", "11:30 AM", "12:00 PM", "12:30 PM", + "1:00 PM", "1:30 PM", "2:00 PM", "2:30 PM", + "3:00 PM", "3:30 PM", "4:00 PM", "4:30 PM", + "5:00 PM" + }; + + // Stores all scheduled appointments in a shared list. private static final ArrayList appointments = new ArrayList<>(); + + // Stores the patient’s name for the appointment. private String name; + + // Stores the haircut or service selected for the appointment. private String haircut; + + // Stores the selected time slot for the appointment. private String timeSlot; + + // Stores the unique patient ID associated with the appointment. private String patientId; + + // Tracks whether the patient has checked in for the appointment. private boolean checkedIn; - // Constructor + // Constructor to instantiate a new AmaniAppointmentMenu object using patient and appointment details. public AmaniAppointmentMenu(BobbyPatient customer, String haircut, String timeSlot) { this.name = customer.getName(); this.haircut = haircut; @@ -22,6 +42,7 @@ public AmaniAppointmentMenu(BobbyPatient customer, String haircut, String timeSl this.checkedIn = false; } + // Displays the appointment menu and processes user selections until the user exits. public static ArrayList appointmentMenu(BobbyPatient customer, Scanner scanner) { boolean running = true; @@ -36,7 +57,9 @@ public static ArrayList appointmentMenu(BobbyPatient custo int choice = readInt(scanner); + // Creates a temporary appointment object to access instance methods. AmaniAppointmentMenu temp = new AmaniAppointmentMenu(customer, "N/A", "N/A"); + switch (choice) { case 1 -> temp.scheduleAppointment(customer, scanner); case 2 -> temp.cancelAppointment(customer); @@ -47,106 +70,140 @@ public static ArrayList appointmentMenu(BobbyPatient custo } } + // Returns the list of all scheduled appointments. return appointments; } + // Schedules a new appointment if the selected slot and patient are valid. public void scheduleAppointment(BobbyPatient customer, Scanner scanner) { System.out.println("\n--- Schedule Appointment ---"); int slotIndex = promptForSlot(scanner); String slot = TIME_SLOTS[slotIndex]; + // Checks whether the selected time slot is already booked. if (findAppointmentBySlot(slot) != null) { System.out.println("That time slot is already booked. Pick another."); return; } + // Checks whether the patient already has an existing appointment. AmaniAppointmentMenu existing = findAppointmentByPatient(customer.getPatientId()); + // Tells the customer to reschedule if they already have an appointment. if (existing != null) { System.out.println("You already have an appointment at " + existing.timeSlot + "."); System.out.println("Cancel it first if you want to reschedule."); return; } + // Prompts the user to enter the haircut that they want. System.out.println("Enter haircut/service (ex: Fade, Trim, Lineup): "); String haircutInput = scanner.nextLine().trim(); + + // Validates that the haircut input is not empty. while (haircutInput.isEmpty()) { System.out.println("Service cannot be empty. Enter haircut/service: "); haircutInput = scanner.nextLine().trim(); } + // Adds the new appointment to the appointments list. appointments.add(new AmaniAppointmentMenu(customer, haircutInput, slot)); - System.out.println("Booked! " + customer.getName() + " at " + slot + " for " + haircutInput + "."); + System.out.println("Booked! " + customer.getName() + " at " + slot + " for " + haircutInput + "."); } + // Cancels the patient’s existing appointment if one exists. public void cancelAppointment(BobbyPatient customer) { System.out.println("\n--- Cancel Appointment ---"); + // Finds the appointment for the customer provided as an argument AmaniAppointmentMenu appt = findAppointmentByPatient(customer.getPatientId()); + + // Checks whether an appointment exists for the patient. if (appt == null) { System.out.println("No appointment found for " + customer.getName() + "."); return; } + + // Removes the appointment from the appointments list. appointments.remove(appt); - System.out.println("Canceled appointment at " + appt.timeSlot + " for " + customer.getName() + "."); + System.out.println("Canceled appointment at " + appt.timeSlot + " for " + customer.getName() + "."); } + // Marks the patient as checked in for their appointment. public void checkIn(BobbyPatient customer) { System.out.println("\n--- Check In ---"); AmaniAppointmentMenu appt = findAppointmentByPatient(customer.getPatientId()); + + // Checks whether an appointment exists before checking in. if (appt == null) { System.out.println("No appointment found for " + customer.getName() + "."); return; } + + // Updates the appointment’s checked-in status to true. appt.setCheckedIn(true); + System.out.println("Checked in: " + appt.name + " | " + appt.timeSlot + " | " + appt.haircut); } + // Displays the full schedule and indicates whether each slot is available or booked. public void viewSchedule() { System.out.println("\n--- Full Schedule ---"); for (String slot : TIME_SLOTS) { AmaniAppointmentMenu appt = findAppointmentBySlot(slot); + + // Displays availability if no appointment exists for the slot. if (appt == null) { System.out.println(slot + " -> Available"); } else { + // Changes output depending on whether the customer has checked in for their appointment. if (appt.checkedIn) { - System.out.println(slot + " -> BOOKED " + appt.name + " (" + appt.haircut + ") Checked In?: Yes" ); + System.out.println(slot + " -> BOOKED " + appt.name + " (" + appt.haircut + ") Checked In?: Yes"); } else { - System.out.println(slot + " -> BOOKED " + appt.name + " (" + appt.haircut + ") Checked In?: No" ); + System.out.println(slot + " -> BOOKED " + appt.name + " (" + appt.haircut + ") Checked In?: No"); } } } } + // Prompts the user to select a valid time slot number. private int promptForSlot(Scanner scanner) { System.out.println("Available time slots:"); + for (int i = 0; i < TIME_SLOTS.length; i++) { System.out.println((i + 1) + ")" + TIME_SLOTS[i]); } - System.out.println("Pick a slot number (1-" + TIME_SLOTS.length + ": "); + System.out.println("Pick a slot number (1-" + TIME_SLOTS.length + "): "); int slotNum = readInt(scanner); + + // Validates that the selected slot number is within range. while (slotNum < 1 || slotNum > TIME_SLOTS.length) { System.out.println("Invalid slot. Pick 1-" + TIME_SLOTS.length + ": "); slotNum = readInt(scanner); } - return slotNum -1; + + // Returns the zero-based index of the selected slot. + return slotNum - 1; } + // Reads and validates an integer input from the user. private static int readInt(Scanner scanner) { while (!scanner.hasNextInt()) { scanner.nextLine(); System.out.println("Enter a number: "); } + int val = scanner.nextInt(); scanner.nextLine(); return val; } + // Searches for an appointment by time slot and returns it if found. private static AmaniAppointmentMenu findAppointmentBySlot(String slot) { for (AmaniAppointmentMenu appt : appointments) { if (appt.timeSlot.equals(slot)) { @@ -156,6 +213,7 @@ private static AmaniAppointmentMenu findAppointmentBySlot(String slot) { return null; } + // Searches for an appointment by patient ID and returns it if found. private static AmaniAppointmentMenu findAppointmentByPatient(String patientId) { for (AmaniAppointmentMenu appt : appointments) { if (appt.patientId.equals(patientId)) { @@ -165,33 +223,40 @@ private static AmaniAppointmentMenu findAppointmentByPatient(String patientId) { return null; } + // Returns a formatted string representation of the appointment. @Override public String toString() { - return "Appointment{name='" + name + "', patientId='" + patientId + "', timeSlot='" + timeSlot + "', haicut='" - + haircut + "'}"; + return "Appointment{name='" + name + "', patientId='" + patientId + + "', timeSlot='" + timeSlot + "', haircut='" + haircut + "'}"; } + // Returns the checked-in status of the appointment. public boolean getCheckedIn() { return this.checkedIn; } + // Updates the checked-in status of the appointment. public void setCheckedIn(boolean checkedIn) { this.checkedIn = checkedIn; } + // Returns the patient’s name associated with the appointment. public String getName() { return this.name; } + // Returns the patient ID associated with the appointment. public String getPatientId() { return this.patientId; } + // Returns the haircut or service associated with the appointment. public String getHaircut() { return this.haircut; } + // Returns the time slot associated with the appointment. public String getTimeSlot() { return this.timeSlot; } -} +} \ No newline at end of file diff --git a/src/main/java/org/codedifferently/BobbyPatient.java b/src/main/java/org/codedifferently/BobbyPatient.java index 1a45b43..b7a5dfa 100644 --- a/src/main/java/org/codedifferently/BobbyPatient.java +++ b/src/main/java/org/codedifferently/BobbyPatient.java @@ -5,7 +5,6 @@ public class BobbyPatient { private String name; private String phoneNumber; private final String patientId; - private String haircut; // Constructor public BobbyPatient(String name, String phoneNumber) { @@ -18,18 +17,10 @@ public String getName() { return name; } - public void setName(String name) { - this.name = name; - } - public String getPhoneNumber() { return phoneNumber; } - public void setPhoneNumber(String phoneNumber) { - this.phoneNumber = phoneNumber; - } - public String getPatientId() { return patientId; } @@ -42,6 +33,4 @@ public String generatePatientId(Random random) { public String toString() { return "\n(Name: " + name + ", Phone: " + phoneNumber + ", PatientId: " + patientId + ")"; } - - -} +} \ No newline at end of file diff --git a/src/main/java/org/codedifferently/JaydenClinicApp.java b/src/main/java/org/codedifferently/JaydenClinicApp.java index 84f5069..d15b26c 100644 --- a/src/main/java/org/codedifferently/JaydenClinicApp.java +++ b/src/main/java/org/codedifferently/JaydenClinicApp.java @@ -3,6 +3,7 @@ public class JaydenClinicApp { public static void main(String[] args) { + // Launches the barbershop system. JaydenClinicSystem.displayOptions(new Scanner(System.in)); } } From 33a02beacdcfa3e2e91c5834fc42762f580772b5 Mon Sep 17 00:00:00 2001 From: Jayden Andrews Date: Sun, 22 Feb 2026 13:18:17 -0500 Subject: [PATCH 08/17] Added comments to BobbyPatient class --- .../java/org/codedifferently/BobbyPatient.java | 16 +++++++++++++++- .../org/codedifferently/JaydenClinicSystem.java | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/codedifferently/BobbyPatient.java b/src/main/java/org/codedifferently/BobbyPatient.java index b7a5dfa..60022d9 100644 --- a/src/main/java/org/codedifferently/BobbyPatient.java +++ b/src/main/java/org/codedifferently/BobbyPatient.java @@ -1,34 +1,48 @@ package org.codedifferently; + import java.util.Random; +// Defines the BobbyPatient class that stores customer information and generates unique IDs. public class BobbyPatient { + + // Stores the patient’s full name. private String name; + + // Stores the patient’s phone number. private String phoneNumber; + + // Stores the unique patient ID that remains constant after creation. private final String patientId; - // Constructor + /* Constructor to instantiates a new BobbyPatient object using the provided name and phone number. + Generates and assigns a unique patient ID during object creation. */ public BobbyPatient(String name, String phoneNumber) { this.name = name; this.phoneNumber = phoneNumber; this.patientId = generatePatientId(new Random()); } + // Returns the patient’s name. public String getName() { return name; } + // Returns the customer’s phone number. public String getPhoneNumber() { return phoneNumber; } + // Returns the customer’s unique ID. public String getPatientId() { return patientId; } + // Generates a unique patient ID using the first three letters of the name and a random five-digit number. public String generatePatientId(Random random) { return name.substring(0, 3).toUpperCase() + random.nextInt(10000, 100000); } + // Returns a formatted string representation of the customer’s information. @Override public String toString() { return "\n(Name: " + name + ", Phone: " + phoneNumber + ", PatientId: " + patientId + ")"; diff --git a/src/main/java/org/codedifferently/JaydenClinicSystem.java b/src/main/java/org/codedifferently/JaydenClinicSystem.java index f292537..2d26195 100644 --- a/src/main/java/org/codedifferently/JaydenClinicSystem.java +++ b/src/main/java/org/codedifferently/JaydenClinicSystem.java @@ -66,8 +66,8 @@ public static void displayOptions(Scanner sc) { } break; case 0: - System.out.println("\nRecords"); if (appointments != null) { + System.out.println("\nElectronic Journal of Completed Appointments"); for (AmaniAppointmentMenu appt: appointments) { if (appt.getCheckedIn()) { System.out.println(appt.getTimeSlot() + " -> [Name: " + appt.getName() + ", " + From 08ab912f82960f48cbd4160a2ad032f997b775c1 Mon Sep 17 00:00:00 2001 From: Jayden Andrews Date: Sun, 22 Feb 2026 13:52:33 -0500 Subject: [PATCH 09/17] Added comments to JaydenClinicSystem --- .../codedifferently/AmaniAppointmentMenu.java | 2 +- .../codedifferently/JaydenClinicSystem.java | 55 ++++++++++++++----- src/main/java/org/codedifferently/Main.java | 17 ------ 3 files changed, 41 insertions(+), 33 deletions(-) delete mode 100644 src/main/java/org/codedifferently/Main.java diff --git a/src/main/java/org/codedifferently/AmaniAppointmentMenu.java b/src/main/java/org/codedifferently/AmaniAppointmentMenu.java index f999365..8eba623 100644 --- a/src/main/java/org/codedifferently/AmaniAppointmentMenu.java +++ b/src/main/java/org/codedifferently/AmaniAppointmentMenu.java @@ -53,7 +53,7 @@ public static ArrayList appointmentMenu(BobbyPatient custo System.out.println("3) Check In"); System.out.println("4) View Schedule"); System.out.println("0) Exit"); - System.out.println("Choose: "); + System.out.print("Choose: "); int choice = readInt(scanner); diff --git a/src/main/java/org/codedifferently/JaydenClinicSystem.java b/src/main/java/org/codedifferently/JaydenClinicSystem.java index 2d26195..03407aa 100644 --- a/src/main/java/org/codedifferently/JaydenClinicSystem.java +++ b/src/main/java/org/codedifferently/JaydenClinicSystem.java @@ -1,27 +1,34 @@ package org.codedifferently; + import java.util.ArrayList; import java.util.Scanner; import java.util.regex.*; +// Defines the main clinic system that manages customers. public class JaydenClinicSystem { + + // Stores all registered customers in the system. private static ArrayList customers = new ArrayList<>(); + // Displays the main menu and processes user selections until the user quits. public static void displayOptions(Scanner sc) { System.out.println("Welcome! What would you like to do today? (Enter a number)\n"); int input; + + // Stores appointment data for generating a journal upon exit. ArrayList appointments = null; do { - // Prints the menu. + // Displays the main menu options to the user. System.out.println("Barber Shop Management System"); - System.out.println("1) Add a new customer."); - System.out.println("2) View all customers."); - System.out.println("3) Manage appointment for a customer."); - System.out.println("4) Search for a customer."); + System.out.println("1) Add a new customer"); + System.out.println("2) View all customers"); + System.out.println("3) Manage appointment for a customer"); + System.out.println("4) Search for a customer"); System.out.println("0) Quit"); System.out.print("Choose: "); - // Validates the input. + // Validates numeric input before processing. if (sc.hasNextInt()) { input = sc.nextInt(); } else { @@ -29,22 +36,28 @@ public static void displayOptions(Scanner sc) { } sc.nextLine(); - // The regex that will be used to match the phone number input + // Defines the regex pattern used to validate phone number input. String regex = "^\\+?1?\\D*?(\\d{3})\\D*?(\\d{3})\\D*?(\\d{4})$"; - // Turns the regex into a pattern object. + + // Compiles the regex string into a Pattern object. Pattern pattern = Pattern.compile(regex); + String phoneNumber; switch (input) { + // Handles the creation and storage of a new customer. case 1: System.out.print("\nEnter your name: "); String name = sc.nextLine(); phoneNumber = formatPhoneNumber(pattern, sc); addCustomer(new BobbyPatient(name, phoneNumber)); break; + // Displays the full list of registered customers. case 2: - System.out.println(getCustomers()); + System.out.println("\nCustomers"); + System.out.println(getCustomers() + "\n"); break; + // Manages appointment scheduling for an existing customer. case 3: phoneNumber = formatPhoneNumber(pattern, sc); BobbyPatient customer = searchCustomer(phoneNumber); @@ -54,17 +67,20 @@ public static void displayOptions(Scanner sc) { System.out.println("Customer not in database. Please add them first.\n"); } break; + // Searches for a customer using their phone number. case 4: phoneNumber = formatPhoneNumber(pattern, sc); BobbyPatient customer2 = searchCustomer(phoneNumber); + // Prints out customer if found. if (customer2 != null) { - System.out.print("Customer found:"); - System.out.println(customer2 + "\n"); + System.out.println("\nCustomer found: " + customer2 + "\n"); + // Tells the user that the customer was not found if they do not exist. } else { System.out.println("Customer not found."); } break; + // Exits the system and prints a journal of completed appointments. case 0: if (appointments != null) { System.out.println("\nElectronic Journal of Completed Appointments"); @@ -78,45 +94,54 @@ public static void displayOptions(Scanner sc) { } System.out.println("\nExiting system..."); break; + + // Handles invalid menu selections. default: System.out.println("\nPlease select a valid option.\n"); } + // Stopping condition. Program will exit when the user inputs 0. } while (input != 0); } + // Adds a new customer to the customer list. public static void addCustomer(BobbyPatient customer) { customers.add(customer); } + // Returns the list of all registered customers. public static ArrayList getCustomers() { return customers; } + // Searches for a customer using their phone number and returns the match if found. public static BobbyPatient searchCustomer(String phoneNumber) { for (BobbyPatient customer : customers) { if (customer.getPhoneNumber().equals(phoneNumber)) { return customer; } } + // Returns null if the customer is not found. return null; } + // Validates and formats the user’s phone number input using the provided pattern. public static String formatPhoneNumber(Pattern pattern, Scanner sc) { while (true) { // Prompts the user to enter their phone number. System.out.print("Enter your phone number: "); String phoneNumber = sc.nextLine(); - // Checks the phone number to see if it matches the pattern. + // Creates a Matcher object to compare input against the pattern. Matcher matcher = pattern.matcher(phoneNumber); - // If the phone number matches the expected structure + // Checks whether the phone number matches the expected format. if (matcher.matches()) { - // Reformat into XXX-XXX-XXXX + // Formats the number into XXX-XXX-XXXX structure. return (matcher.group(1) + "-" + matcher.group(2) + "-" + matcher.group(3)); } else { + // Displays an error message if validation fails. System.out.println("\nInvalid phone number. Please try again.\n"); } } } -} +} \ No newline at end of file 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 7016318f13995d7f5e6be1c54aa091081c6d5ca6 Mon Sep 17 00:00:00 2001 From: Jayden Andrews Date: Sun, 22 Feb 2026 14:52:03 -0500 Subject: [PATCH 10/17] Implemented handling of multiple uses of the same phone number --- .../codedifferently/JaydenClinicSystem.java | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/codedifferently/JaydenClinicSystem.java b/src/main/java/org/codedifferently/JaydenClinicSystem.java index 03407aa..86eef4c 100644 --- a/src/main/java/org/codedifferently/JaydenClinicSystem.java +++ b/src/main/java/org/codedifferently/JaydenClinicSystem.java @@ -60,7 +60,7 @@ public static void displayOptions(Scanner sc) { // Manages appointment scheduling for an existing customer. case 3: phoneNumber = formatPhoneNumber(pattern, sc); - BobbyPatient customer = searchCustomer(phoneNumber); + BobbyPatient customer = searchCustomer(phoneNumber, sc); if (customer != null) { appointments = AmaniAppointmentMenu.appointmentMenu(customer, sc); } else { @@ -70,7 +70,7 @@ public static void displayOptions(Scanner sc) { // Searches for a customer using their phone number. case 4: phoneNumber = formatPhoneNumber(pattern, sc); - BobbyPatient customer2 = searchCustomer(phoneNumber); + BobbyPatient customer2 = searchCustomer(phoneNumber, sc); // Prints out customer if found. if (customer2 != null) { @@ -114,14 +114,32 @@ public static ArrayList getCustomers() { } // Searches for a customer using their phone number and returns the match if found. - public static BobbyPatient searchCustomer(String phoneNumber) { + public static BobbyPatient searchCustomer(String phoneNumber, Scanner sc) { + ArrayList customersFound = new ArrayList<>(); for (BobbyPatient customer : customers) { if (customer.getPhoneNumber().equals(phoneNumber)) { - return customer; + customersFound.add(customer); } } // Returns null if the customer is not found. - return null; + if (customersFound.isEmpty()) { + return null; + } else if (customersFound.size() == 1) { + return customersFound.getFirst(); + } else { + while(true) { + System.out.println("Multiple customers found: " + customersFound); + System.out.print("Enter patient id: "); + String id = sc.nextLine(); + for (BobbyPatient customer : customers) { + if (customer.getPatientId().equals(id)) { + return customer; + } else { + System.out.println("Invalid patient id"); + } + } + } + } } // Validates and formats the user’s phone number input using the provided pattern. From 8a196633ada82f709f2abdcd1567d3965c4aca8a Mon Sep 17 00:00:00 2001 From: Jayden Andrews Date: Sun, 22 Feb 2026 15:22:21 -0500 Subject: [PATCH 11/17] Formatted output --- .../codedifferently/JaydenClinicSystem.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/codedifferently/JaydenClinicSystem.java b/src/main/java/org/codedifferently/JaydenClinicSystem.java index 86eef4c..c61237f 100644 --- a/src/main/java/org/codedifferently/JaydenClinicSystem.java +++ b/src/main/java/org/codedifferently/JaydenClinicSystem.java @@ -12,7 +12,7 @@ public class JaydenClinicSystem { // Displays the main menu and processes user selections until the user quits. public static void displayOptions(Scanner sc) { - System.out.println("Welcome! What would you like to do today? (Enter a number)\n"); + System.out.println("Welcome! What would you like to do today? (Enter a number)"); int input; // Stores appointment data for generating a journal upon exit. @@ -20,7 +20,7 @@ public static void displayOptions(Scanner sc) { do { // Displays the main menu options to the user. - System.out.println("Barber Shop Management System"); + System.out.println("\n=== Barber Shop Management Menu ==="); System.out.println("1) Add a new customer"); System.out.println("2) View all customers"); System.out.println("3) Manage appointment for a customer"); @@ -55,7 +55,7 @@ public static void displayOptions(Scanner sc) { // Displays the full list of registered customers. case 2: System.out.println("\nCustomers"); - System.out.println(getCustomers() + "\n"); + System.out.println(getCustomers()); break; // Manages appointment scheduling for an existing customer. case 3: @@ -64,7 +64,7 @@ public static void displayOptions(Scanner sc) { if (customer != null) { appointments = AmaniAppointmentMenu.appointmentMenu(customer, sc); } else { - System.out.println("Customer not in database. Please add them first.\n"); + System.out.println("\nCustomer not in database. Please add them first."); } break; // Searches for a customer using their phone number. @@ -74,15 +74,16 @@ public static void displayOptions(Scanner sc) { // Prints out customer if found. if (customer2 != null) { - System.out.println("\nCustomer found: " + customer2 + "\n"); + System.out.println("\nCustomer found: " + customer2); // Tells the user that the customer was not found if they do not exist. } else { - System.out.println("Customer not found."); + System.out.println("\nCustomer not found."); } break; // Exits the system and prints a journal of completed appointments. case 0: - if (appointments != null) { + // Prints out electronic journal if appointments have happened today. + if (appointments != null && !(appointments.isEmpty())) { System.out.println("\nElectronic Journal of Completed Appointments"); for (AmaniAppointmentMenu appt: appointments) { if (appt.getCheckedIn()) { @@ -97,7 +98,7 @@ public static void displayOptions(Scanner sc) { // Handles invalid menu selections. default: - System.out.println("\nPlease select a valid option.\n"); + System.out.println("\nPlease select a valid option."); } // Stopping condition. Program will exit when the user inputs 0. } while (input != 0); @@ -106,6 +107,7 @@ public static void displayOptions(Scanner sc) { // Adds a new customer to the customer list. public static void addCustomer(BobbyPatient customer) { customers.add(customer); + System.out.println("\nCustomer " + customer.getName() + " (" + customer.getPatientId() + ") added!"); } // Returns the list of all registered customers. @@ -124,20 +126,21 @@ public static BobbyPatient searchCustomer(String phoneNumber, Scanner sc) { // Returns null if the customer is not found. if (customersFound.isEmpty()) { return null; + // Returns the customer if there are no duplicate phoneNumber. } else if (customersFound.size() == 1) { return customersFound.getFirst(); + // Prompts the user to select by patient id since more than one customer used the same phone number. } else { + System.out.println("\nMultiple customers found: " + customersFound + "\n"); while(true) { - System.out.println("Multiple customers found: " + customersFound); System.out.print("Enter patient id: "); String id = sc.nextLine(); for (BobbyPatient customer : customers) { if (customer.getPatientId().equals(id)) { return customer; - } else { - System.out.println("Invalid patient id"); } } + System.out.println("Invalid patient id. Try again.\n"); } } } From b5d9a88922fa7094da686dd62dd5feecd65f51fd Mon Sep 17 00:00:00 2001 From: Jayden Andrews Date: Sun, 22 Feb 2026 15:24:09 -0500 Subject: [PATCH 12/17] Formatted output --- src/main/java/org/codedifferently/JaydenClinicSystem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/codedifferently/JaydenClinicSystem.java b/src/main/java/org/codedifferently/JaydenClinicSystem.java index c61237f..cdf8589 100644 --- a/src/main/java/org/codedifferently/JaydenClinicSystem.java +++ b/src/main/java/org/codedifferently/JaydenClinicSystem.java @@ -126,7 +126,7 @@ public static BobbyPatient searchCustomer(String phoneNumber, Scanner sc) { // Returns null if the customer is not found. if (customersFound.isEmpty()) { return null; - // Returns the customer if there are no duplicate phoneNumber. + // Returns the customer if there are no duplicate phone numbers. } else if (customersFound.size() == 1) { return customersFound.getFirst(); // Prompts the user to select by patient id since more than one customer used the same phone number. From 462e110ea05c61cfc9091391fab4c736c83cd095 Mon Sep 17 00:00:00 2001 From: Jayden Andrews Date: Sun, 22 Feb 2026 19:54:41 -0500 Subject: [PATCH 13/17] Renamed class --- ...intmentMenu.java => AmaniAppointment.java} | 28 +++++++++---------- .../codedifferently/JaydenClinicSystem.java | 8 +++--- 2 files changed, 18 insertions(+), 18 deletions(-) rename src/main/java/org/codedifferently/{AmaniAppointmentMenu.java => AmaniAppointment.java} (89%) diff --git a/src/main/java/org/codedifferently/AmaniAppointmentMenu.java b/src/main/java/org/codedifferently/AmaniAppointment.java similarity index 89% rename from src/main/java/org/codedifferently/AmaniAppointmentMenu.java rename to src/main/java/org/codedifferently/AmaniAppointment.java index 8eba623..487d240 100644 --- a/src/main/java/org/codedifferently/AmaniAppointmentMenu.java +++ b/src/main/java/org/codedifferently/AmaniAppointment.java @@ -4,7 +4,7 @@ import java.util.Scanner; // Defines the AmaniAppointmentMenu class that manages appointment scheduling and tracking. -public class AmaniAppointmentMenu { +public class AmaniAppointment { // Stores all available appointment time slots for the day. private static final String[] TIME_SLOTS = { @@ -16,7 +16,7 @@ public class AmaniAppointmentMenu { }; // Stores all scheduled appointments in a shared list. - private static final ArrayList appointments = new ArrayList<>(); + private static final ArrayList appointments = new ArrayList<>(); // Stores the patient’s name for the appointment. private String name; @@ -34,7 +34,7 @@ public class AmaniAppointmentMenu { private boolean checkedIn; // Constructor to instantiate a new AmaniAppointmentMenu object using patient and appointment details. - public AmaniAppointmentMenu(BobbyPatient customer, String haircut, String timeSlot) { + public AmaniAppointment(BobbyPatient customer, String haircut, String timeSlot) { this.name = customer.getName(); this.haircut = haircut; this.timeSlot = timeSlot; @@ -43,7 +43,7 @@ public AmaniAppointmentMenu(BobbyPatient customer, String haircut, String timeSl } // Displays the appointment menu and processes user selections until the user exits. - public static ArrayList appointmentMenu(BobbyPatient customer, Scanner scanner) { + public static ArrayList appointmentMenu(BobbyPatient customer, Scanner scanner) { boolean running = true; while (running) { @@ -58,7 +58,7 @@ public static ArrayList appointmentMenu(BobbyPatient custo int choice = readInt(scanner); // Creates a temporary appointment object to access instance methods. - AmaniAppointmentMenu temp = new AmaniAppointmentMenu(customer, "N/A", "N/A"); + AmaniAppointment temp = new AmaniAppointment(customer, "N/A", "N/A"); switch (choice) { case 1 -> temp.scheduleAppointment(customer, scanner); @@ -88,7 +88,7 @@ public void scheduleAppointment(BobbyPatient customer, Scanner scanner) { } // Checks whether the patient already has an existing appointment. - AmaniAppointmentMenu existing = findAppointmentByPatient(customer.getPatientId()); + AmaniAppointment existing = findAppointmentByPatient(customer.getPatientId()); // Tells the customer to reschedule if they already have an appointment. if (existing != null) { System.out.println("You already have an appointment at " + existing.timeSlot + "."); @@ -107,7 +107,7 @@ public void scheduleAppointment(BobbyPatient customer, Scanner scanner) { } // Adds the new appointment to the appointments list. - appointments.add(new AmaniAppointmentMenu(customer, haircutInput, slot)); + appointments.add(new AmaniAppointment(customer, haircutInput, slot)); System.out.println("Booked! " + customer.getName() + " at " + slot + " for " + haircutInput + "."); } @@ -117,7 +117,7 @@ public void cancelAppointment(BobbyPatient customer) { System.out.println("\n--- Cancel Appointment ---"); // Finds the appointment for the customer provided as an argument - AmaniAppointmentMenu appt = findAppointmentByPatient(customer.getPatientId()); + AmaniAppointment appt = findAppointmentByPatient(customer.getPatientId()); // Checks whether an appointment exists for the patient. if (appt == null) { @@ -135,7 +135,7 @@ public void cancelAppointment(BobbyPatient customer) { public void checkIn(BobbyPatient customer) { System.out.println("\n--- Check In ---"); - AmaniAppointmentMenu appt = findAppointmentByPatient(customer.getPatientId()); + AmaniAppointment appt = findAppointmentByPatient(customer.getPatientId()); // Checks whether an appointment exists before checking in. if (appt == null) { @@ -154,7 +154,7 @@ public void viewSchedule() { System.out.println("\n--- Full Schedule ---"); for (String slot : TIME_SLOTS) { - AmaniAppointmentMenu appt = findAppointmentBySlot(slot); + AmaniAppointment appt = findAppointmentBySlot(slot); // Displays availability if no appointment exists for the slot. if (appt == null) { @@ -204,8 +204,8 @@ private static int readInt(Scanner scanner) { } // Searches for an appointment by time slot and returns it if found. - private static AmaniAppointmentMenu findAppointmentBySlot(String slot) { - for (AmaniAppointmentMenu appt : appointments) { + private static AmaniAppointment findAppointmentBySlot(String slot) { + for (AmaniAppointment appt : appointments) { if (appt.timeSlot.equals(slot)) { return appt; } @@ -214,8 +214,8 @@ private static AmaniAppointmentMenu findAppointmentBySlot(String slot) { } // Searches for an appointment by patient ID and returns it if found. - private static AmaniAppointmentMenu findAppointmentByPatient(String patientId) { - for (AmaniAppointmentMenu appt : appointments) { + private static AmaniAppointment findAppointmentByPatient(String patientId) { + for (AmaniAppointment appt : appointments) { if (appt.patientId.equals(patientId)) { return appt; } diff --git a/src/main/java/org/codedifferently/JaydenClinicSystem.java b/src/main/java/org/codedifferently/JaydenClinicSystem.java index cdf8589..a5bfaba 100644 --- a/src/main/java/org/codedifferently/JaydenClinicSystem.java +++ b/src/main/java/org/codedifferently/JaydenClinicSystem.java @@ -16,7 +16,7 @@ public static void displayOptions(Scanner sc) { int input; // Stores appointment data for generating a journal upon exit. - ArrayList appointments = null; + ArrayList appointments = null; do { // Displays the main menu options to the user. @@ -62,7 +62,7 @@ public static void displayOptions(Scanner sc) { phoneNumber = formatPhoneNumber(pattern, sc); BobbyPatient customer = searchCustomer(phoneNumber, sc); if (customer != null) { - appointments = AmaniAppointmentMenu.appointmentMenu(customer, sc); + appointments = AmaniAppointment.appointmentMenu(customer, sc); } else { System.out.println("\nCustomer not in database. Please add them first."); } @@ -85,7 +85,7 @@ public static void displayOptions(Scanner sc) { // Prints out electronic journal if appointments have happened today. if (appointments != null && !(appointments.isEmpty())) { System.out.println("\nElectronic Journal of Completed Appointments"); - for (AmaniAppointmentMenu appt: appointments) { + for (AmaniAppointment appt: appointments) { if (appt.getCheckedIn()) { System.out.println(appt.getTimeSlot() + " -> [Name: " + appt.getName() + ", " + "Patient Id: " + appt.getPatientId() + ", " + @@ -133,7 +133,7 @@ public static BobbyPatient searchCustomer(String phoneNumber, Scanner sc) { } else { System.out.println("\nMultiple customers found: " + customersFound + "\n"); while(true) { - System.out.print("Enter patient id: "); + System.out.print("Enter patient id (CASE SENSITIVE): "); String id = sc.nextLine(); for (BobbyPatient customer : customers) { if (customer.getPatientId().equals(id)) { From 4877118905ddc5178a7764bf6a88ee4da46369f0 Mon Sep 17 00:00:00 2001 From: Jayden Andrews Date: Sun, 22 Feb 2026 20:08:52 -0500 Subject: [PATCH 14/17] Squashed bug that woudnt allow for names less than 3 characters --- .../org/codedifferently/AmaniAppointment.java | 44 +++++++++---------- .../org/codedifferently/BobbyPatient.java | 30 ++++++++----- .../codedifferently/JaydenClinicSystem.java | 12 ++--- 3 files changed, 46 insertions(+), 40 deletions(-) diff --git a/src/main/java/org/codedifferently/AmaniAppointment.java b/src/main/java/org/codedifferently/AmaniAppointment.java index 487d240..cc0b18c 100644 --- a/src/main/java/org/codedifferently/AmaniAppointment.java +++ b/src/main/java/org/codedifferently/AmaniAppointment.java @@ -18,7 +18,7 @@ public class AmaniAppointment { // Stores all scheduled appointments in a shared list. private static final ArrayList appointments = new ArrayList<>(); - // Stores the patient’s name for the appointment. + // Stores the customer’s name for the appointment. private String name; // Stores the haircut or service selected for the appointment. @@ -27,18 +27,18 @@ public class AmaniAppointment { // Stores the selected time slot for the appointment. private String timeSlot; - // Stores the unique patient ID associated with the appointment. - private String patientId; + // Stores the unique customer ID associated with the appointment. + private String customerId; - // Tracks whether the patient has checked in for the appointment. + // Tracks whether the customer has checked in for the appointment. private boolean checkedIn; - // Constructor to instantiate a new AmaniAppointmentMenu object using patient and appointment details. + // Constructor to instantiate a new AmaniAppointmentMenu object using customer and appointment details. public AmaniAppointment(BobbyPatient customer, String haircut, String timeSlot) { this.name = customer.getName(); this.haircut = haircut; this.timeSlot = timeSlot; - this.patientId = customer.getPatientId(); + this.customerId = customer.getCustomerId(); this.checkedIn = false; } @@ -74,7 +74,7 @@ public static ArrayList appointmentMenu(BobbyPatient customer, return appointments; } - // Schedules a new appointment if the selected slot and patient are valid. + // Schedules a new appointment if the selected slot and customer are valid. public void scheduleAppointment(BobbyPatient customer, Scanner scanner) { System.out.println("\n--- Schedule Appointment ---"); @@ -87,8 +87,8 @@ public void scheduleAppointment(BobbyPatient customer, Scanner scanner) { return; } - // Checks whether the patient already has an existing appointment. - AmaniAppointment existing = findAppointmentByPatient(customer.getPatientId()); + // Checks whether the customer already has an existing appointment. + AmaniAppointment existing = findAppointmentByCustomer(customer.getCustomerId()); // Tells the customer to reschedule if they already have an appointment. if (existing != null) { System.out.println("You already have an appointment at " + existing.timeSlot + "."); @@ -112,14 +112,14 @@ public void scheduleAppointment(BobbyPatient customer, Scanner scanner) { System.out.println("Booked! " + customer.getName() + " at " + slot + " for " + haircutInput + "."); } - // Cancels the patient’s existing appointment if one exists. + // Cancels customer’s existing appointment if one exists. public void cancelAppointment(BobbyPatient customer) { System.out.println("\n--- Cancel Appointment ---"); // Finds the appointment for the customer provided as an argument - AmaniAppointment appt = findAppointmentByPatient(customer.getPatientId()); + AmaniAppointment appt = findAppointmentByCustomer(customer.getCustomerId()); - // Checks whether an appointment exists for the patient. + // Checks whether an appointment exists for the customer. if (appt == null) { System.out.println("No appointment found for " + customer.getName() + "."); return; @@ -131,11 +131,11 @@ public void cancelAppointment(BobbyPatient customer) { System.out.println("Canceled appointment at " + appt.timeSlot + " for " + customer.getName() + "."); } - // Marks the patient as checked in for their appointment. + // Marks the customer as checked in for their appointment. public void checkIn(BobbyPatient customer) { System.out.println("\n--- Check In ---"); - AmaniAppointment appt = findAppointmentByPatient(customer.getPatientId()); + AmaniAppointment appt = findAppointmentByCustomer(customer.getCustomerId()); // Checks whether an appointment exists before checking in. if (appt == null) { @@ -213,10 +213,10 @@ private static AmaniAppointment findAppointmentBySlot(String slot) { return null; } - // Searches for an appointment by patient ID and returns it if found. - private static AmaniAppointment findAppointmentByPatient(String patientId) { + // Searches for an appointment by customer ID and returns it if found. + private static AmaniAppointment findAppointmentByCustomer(String customerId) { for (AmaniAppointment appt : appointments) { - if (appt.patientId.equals(patientId)) { + if (appt.customerId.equals(customerId)) { return appt; } } @@ -226,7 +226,7 @@ private static AmaniAppointment findAppointmentByPatient(String patientId) { // Returns a formatted string representation of the appointment. @Override public String toString() { - return "Appointment{name='" + name + "', patientId='" + patientId + + return "Appointment{name='" + name + "', customerId='" + customerId + "', timeSlot='" + timeSlot + "', haircut='" + haircut + "'}"; } @@ -240,14 +240,14 @@ public void setCheckedIn(boolean checkedIn) { this.checkedIn = checkedIn; } - // Returns the patient’s name associated with the appointment. + // Returns the customer’s name associated with the appointment. public String getName() { return this.name; } - // Returns the patient ID associated with the appointment. - public String getPatientId() { - return this.patientId; + // Returns the customer ID associated with the appointment. + public String getCustomerId() { + return this.customerId; } // Returns the haircut or service associated with the appointment. diff --git a/src/main/java/org/codedifferently/BobbyPatient.java b/src/main/java/org/codedifferently/BobbyPatient.java index 60022d9..7dc23ef 100644 --- a/src/main/java/org/codedifferently/BobbyPatient.java +++ b/src/main/java/org/codedifferently/BobbyPatient.java @@ -5,24 +5,24 @@ // Defines the BobbyPatient class that stores customer information and generates unique IDs. public class BobbyPatient { - // Stores the patient’s full name. + // Stores the customer’s full name. private String name; - // Stores the patient’s phone number. + // Stores the customer’s phone number. private String phoneNumber; // Stores the unique patient ID that remains constant after creation. - private final String patientId; + private final String customerId; /* Constructor to instantiates a new BobbyPatient object using the provided name and phone number. - Generates and assigns a unique patient ID during object creation. */ + Generates and assigns a unique customer ID during object creation. */ public BobbyPatient(String name, String phoneNumber) { this.name = name; this.phoneNumber = phoneNumber; - this.patientId = generatePatientId(new Random()); + this.customerId = generateCustomerId(new Random()); } - // Returns the patient’s name. + // Returns the customer’s name. public String getName() { return name; } @@ -33,18 +33,24 @@ public String getPhoneNumber() { } // Returns the customer’s unique ID. - public String getPatientId() { - return patientId; + public String getCustomerId() { + return customerId; } - // Generates a unique patient ID using the first three letters of the name and a random five-digit number. - public String generatePatientId(Random random) { - return name.substring(0, 3).toUpperCase() + random.nextInt(10000, 100000); + // Generates a unique customer ID using the first three letters of the name and a random five-digit number. + public String generateCustomerId(Random random) { + String prefix; + if (name.length() >= 3) { + prefix = name.substring(0, 3).toUpperCase(); + } else { + prefix = name.toUpperCase(); + } + return prefix + random.nextInt(10000, 100000); } // Returns a formatted string representation of the customer’s information. @Override public String toString() { - return "\n(Name: " + name + ", Phone: " + phoneNumber + ", PatientId: " + patientId + ")"; + return "\n(Name: " + name + ", Phone: " + phoneNumber + ", PatientId: " + customerId + ")"; } } \ No newline at end of file diff --git a/src/main/java/org/codedifferently/JaydenClinicSystem.java b/src/main/java/org/codedifferently/JaydenClinicSystem.java index a5bfaba..43e7f0b 100644 --- a/src/main/java/org/codedifferently/JaydenClinicSystem.java +++ b/src/main/java/org/codedifferently/JaydenClinicSystem.java @@ -88,7 +88,7 @@ public static void displayOptions(Scanner sc) { for (AmaniAppointment appt: appointments) { if (appt.getCheckedIn()) { System.out.println(appt.getTimeSlot() + " -> [Name: " + appt.getName() + ", " + - "Patient Id: " + appt.getPatientId() + ", " + + "Customer Id: " + appt.getCustomerId() + ", " + "Haircut: " + appt.getHaircut() + "]"); } } @@ -107,7 +107,7 @@ public static void displayOptions(Scanner sc) { // Adds a new customer to the customer list. public static void addCustomer(BobbyPatient customer) { customers.add(customer); - System.out.println("\nCustomer " + customer.getName() + " (" + customer.getPatientId() + ") added!"); + System.out.println("\nCustomer " + customer.getName() + " (" + customer.getCustomerId() + ") added!"); } // Returns the list of all registered customers. @@ -129,18 +129,18 @@ public static BobbyPatient searchCustomer(String phoneNumber, Scanner sc) { // Returns the customer if there are no duplicate phone numbers. } else if (customersFound.size() == 1) { return customersFound.getFirst(); - // Prompts the user to select by patient id since more than one customer used the same phone number. + // Prompts the user to select by customer id since more than one customer used the same phone number. } else { System.out.println("\nMultiple customers found: " + customersFound + "\n"); while(true) { - System.out.print("Enter patient id (CASE SENSITIVE): "); + System.out.print("Enter customer id (CASE SENSITIVE): "); String id = sc.nextLine(); for (BobbyPatient customer : customers) { - if (customer.getPatientId().equals(id)) { + if (customer.getCustomerId().equals(id)) { return customer; } } - System.out.println("Invalid patient id. Try again.\n"); + System.out.println("Invalid customer id. Try again.\n"); } } } From af1484d8068823cf78642ba485b1b9d4d6be89b9 Mon Sep 17 00:00:00 2001 From: Jayden Andrews Date: Sun, 22 Feb 2026 20:22:38 -0500 Subject: [PATCH 15/17] Did more formatting --- .../org/codedifferently/AmaniAppointment.java | 2 +- .../codedifferently/JaydenClinicSystem.java | 36 ++++++++++++++----- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/codedifferently/AmaniAppointment.java b/src/main/java/org/codedifferently/AmaniAppointment.java index cc0b18c..b626b74 100644 --- a/src/main/java/org/codedifferently/AmaniAppointment.java +++ b/src/main/java/org/codedifferently/AmaniAppointment.java @@ -175,7 +175,7 @@ private int promptForSlot(Scanner scanner) { System.out.println("Available time slots:"); for (int i = 0; i < TIME_SLOTS.length; i++) { - System.out.println((i + 1) + ")" + TIME_SLOTS[i]); + System.out.println((i + 1) + ") " + TIME_SLOTS[i]); } System.out.println("Pick a slot number (1-" + TIME_SLOTS.length + "): "); diff --git a/src/main/java/org/codedifferently/JaydenClinicSystem.java b/src/main/java/org/codedifferently/JaydenClinicSystem.java index 43e7f0b..d076881 100644 --- a/src/main/java/org/codedifferently/JaydenClinicSystem.java +++ b/src/main/java/org/codedifferently/JaydenClinicSystem.java @@ -37,19 +37,19 @@ public static void displayOptions(Scanner sc) { sc.nextLine(); // Defines the regex pattern used to validate phone number input. - String regex = "^\\+?1?\\D*?(\\d{3})\\D*?(\\d{3})\\D*?(\\d{4})$"; + String phoneRegex = "^\\+?1?\\D*?(\\d{3})\\D*?(\\d{3})\\D*?(\\d{4})$"; // Compiles the regex string into a Pattern object. - Pattern pattern = Pattern.compile(regex); + Pattern phonePattern = Pattern.compile(phoneRegex); + String name; String phoneNumber; switch (input) { // Handles the creation and storage of a new customer. case 1: - System.out.print("\nEnter your name: "); - String name = sc.nextLine(); - phoneNumber = formatPhoneNumber(pattern, sc); + name = validateName(sc); + phoneNumber = formatPhoneNumber(phonePattern, sc); addCustomer(new BobbyPatient(name, phoneNumber)); break; // Displays the full list of registered customers. @@ -59,7 +59,7 @@ public static void displayOptions(Scanner sc) { break; // Manages appointment scheduling for an existing customer. case 3: - phoneNumber = formatPhoneNumber(pattern, sc); + phoneNumber = formatPhoneNumber(phonePattern, sc); BobbyPatient customer = searchCustomer(phoneNumber, sc); if (customer != null) { appointments = AmaniAppointment.appointmentMenu(customer, sc); @@ -69,7 +69,7 @@ public static void displayOptions(Scanner sc) { break; // Searches for a customer using their phone number. case 4: - phoneNumber = formatPhoneNumber(pattern, sc); + phoneNumber = formatPhoneNumber(phonePattern, sc); BobbyPatient customer2 = searchCustomer(phoneNumber, sc); // Prints out customer if found. @@ -145,11 +145,31 @@ public static BobbyPatient searchCustomer(String phoneNumber, Scanner sc) { } } + // Validates that the user's name input contains only permitted characters. + public static String validateName(Scanner sc) { + // Repeats continuously until valid input is provided. + while (true) { + // Prompts the user to enter their name. + System.out.print("\nEnter a name: "); + String name = sc.nextLine(); + + // Checks whether the input matches the required name pattern. + // Allows letters and optionally single spaces, hyphens, or apostrophes between words. + if (name.matches("^[a-zA-Z]+([ '-][a-zA-Z]+)*$")) { + // Returns the validated name if it meets the pattern requirements. + return name; + } else { + // Displays an error message if validation fails. + System.out.println("\nInvalid name. Please use letters only."); + } + } + } + // Validates and formats the user’s phone number input using the provided pattern. public static String formatPhoneNumber(Pattern pattern, Scanner sc) { while (true) { // Prompts the user to enter their phone number. - System.out.print("Enter your phone number: "); + System.out.print("Enter a phone number: "); String phoneNumber = sc.nextLine(); // Creates a Matcher object to compare input against the pattern. From 8e907b42e754fe80671342577207904f9b74bdb4 Mon Sep 17 00:00:00 2001 From: Jayden Andrews Date: Mon, 23 Feb 2026 08:49:59 -0500 Subject: [PATCH 16/17] Finishing touches --- src/main/java/org/codedifferently/BobbyPatient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/codedifferently/BobbyPatient.java b/src/main/java/org/codedifferently/BobbyPatient.java index 7dc23ef..9dc2fd8 100644 --- a/src/main/java/org/codedifferently/BobbyPatient.java +++ b/src/main/java/org/codedifferently/BobbyPatient.java @@ -51,6 +51,6 @@ public String generateCustomerId(Random random) { // Returns a formatted string representation of the customer’s information. @Override public String toString() { - return "\n(Name: " + name + ", Phone: " + phoneNumber + ", PatientId: " + customerId + ")"; + return "\n(Name: " + name + ", Phone: " + phoneNumber + ", Customer Id: " + customerId + ")"; } } \ No newline at end of file From 9c38280de926dc1cfbf378fd7c0bd2e96c51643e Mon Sep 17 00:00:00 2001 From: Jayden Andrews Date: Mon, 23 Feb 2026 09:42:10 -0500 Subject: [PATCH 17/17] Changed formatting slightly --- src/main/java/org/codedifferently/AmaniAppointment.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/codedifferently/AmaniAppointment.java b/src/main/java/org/codedifferently/AmaniAppointment.java index b626b74..93f2804 100644 --- a/src/main/java/org/codedifferently/AmaniAppointment.java +++ b/src/main/java/org/codedifferently/AmaniAppointment.java @@ -97,19 +97,19 @@ public void scheduleAppointment(BobbyPatient customer, Scanner scanner) { } // Prompts the user to enter the haircut that they want. - System.out.println("Enter haircut/service (ex: Fade, Trim, Lineup): "); + System.out.print("Enter haircut/service (ex: Fade, Trim, Lineup): "); String haircutInput = scanner.nextLine().trim(); // Validates that the haircut input is not empty. while (haircutInput.isEmpty()) { - System.out.println("Service cannot be empty. Enter haircut/service: "); + System.out.print("Service cannot be empty. Enter haircut/service: "); haircutInput = scanner.nextLine().trim(); } // Adds the new appointment to the appointments list. appointments.add(new AmaniAppointment(customer, haircutInput, slot)); - System.out.println("Booked! " + customer.getName() + " at " + slot + " for " + haircutInput + "."); + System.out.println("\nBooked! " + customer.getName() + " at " + slot + " for " + haircutInput + "."); } // Cancels customer’s existing appointment if one exists. @@ -178,7 +178,7 @@ private int promptForSlot(Scanner scanner) { System.out.println((i + 1) + ") " + TIME_SLOTS[i]); } - System.out.println("Pick a slot number (1-" + TIME_SLOTS.length + "): "); + System.out.print("Pick a slot number (1-" + TIME_SLOTS.length + "): "); int slotNum = readInt(scanner); // Validates that the selected slot number is within range.