Skip to content

Commit

Permalink
Bug Fix: error with variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
coraleaf0602 committed Oct 8, 2024
1 parent 50a5fba commit 77e873b
Showing 1 changed file with 33 additions and 32 deletions.
65 changes: 33 additions & 32 deletions src/main/java/bookbob/functions/CommandHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,35 @@ public class CommandHandler {

// Prints output for help command
public void help() {
System.out.println("+-----------+---------------------------------------+---------------------------------+\n" +
"| Action | Format | Example |\n" +
"+-----------+---------------------------------------+---------------------------------+\n" +
"| Help | help | help |\n" +
"+-----------+---------------------------------------+---------------------------------+\n" +
"| Add | add n/NAME ic/NRIC [p/PHONE_NUMBER] | add n/James Ho ic/S9534567A |\n" +
"| | [d/DIAGNOSIS] [m/MEDICATION] | p/91234567 d/Asthma m/Albuterol |\n" +
"| | [ha/HOME_ADDRESS] [dob/DATE_OF_BIRTH] | ha/NUS-PGPR dob/13121995 |\n" +
"+-----------+---------------------------------------+---------------------------------+\n" +
"| List | list | list |\n" +
"+-----------+---------------------------------------+---------------------------------+\n" +
"| Find | find NAME [KEYWORDS] OR | find NRIC S1234 |\n" +
"| | find NRIC [KEYWORDS] OR | |\n" +
"| | find PHONE_NUMBER [KEYWORDS] OR | |\n" +
"| | find DIAGNOSIS [KEYWORDS] OR | |\n" +
"| | find MEDICATION [KEYWORDS] OR | |\n" +
"| | find HOME_ADDRESS [KEYWORDS] OR | |\n" +
"| | find DATE_OF_BIRTH [KEYWORDS] | |\n" +
"+-----------+---------------------------------------+---------------------------------+\n" +
"| Delete | delete NRIC | delete S9534567A |\n" +
"+-----------+---------------------------------------+---------------------------------+\n" +
"| Save | save(automatic) | save |\n" +
"+-----------+---------------------------------------+---------------------------------+\n" +
"| Retrieve/ | retrieve or import | retrieve |\n" +
"| Import | (automatic) | |\n" +
"+-----------+---------------------------------------+---------------------------------+\n" +
"| Exit | exit | exit |\n" +
"+-----------+---------------------------------------+---------------------------------+");
System.out.println("""
+-----------+---------------------------------------+---------------------------------+
| Action | Format | Example |
+-----------+---------------------------------------+---------------------------------+
| Help | help | help |
+-----------+---------------------------------------+---------------------------------+
| Add | add n/NAME ic/NRIC [p/PHONE_NUMBER] | add n/James Ho ic/S9534567A |
| | [d/DIAGNOSIS] [m/MEDICATION] | p/91234567 d/Asthma m/Albuterol |
| | [ha/HOME_ADDRESS] [dob/DATE_OF_BIRTH] | ha/NUS-PGPR dob/13121995 |
+-----------+---------------------------------------+---------------------------------+
| List | list | list |
+-----------+---------------------------------------+---------------------------------+
| Find | find NAME [KEYWORDS] OR | find NRIC S1234 |
| | find NRIC [KEYWORDS] OR | |
| | find PHONE_NUMBER [KEYWORDS] OR | |
| | find DIAGNOSIS [KEYWORDS] OR | |
| | find MEDICATION [KEYWORDS] OR | |
| | find HOME_ADDRESS [KEYWORDS] OR | |
| | find DATE_OF_BIRTH [KEYWORDS] | |
+-----------+---------------------------------------+---------------------------------+
| Delete | delete NRIC | delete S9534567A |
+-----------+---------------------------------------+---------------------------------+
| Save | save(automatic) | save |
+-----------+---------------------------------------+---------------------------------+
| Retrieve/ | retrieve or import | retrieve |
| Import | (automatic) | |
+-----------+---------------------------------------+---------------------------------+
| Exit | exit | exit |
+-----------+---------------------------------------+---------------------------------+""");
}

public void add(String input, Records records) {
Expand All @@ -64,9 +65,9 @@ public void add(String input, Records records) {
// Extract NRIC
int phoneStart = input.indexOf("p/");
if (nricStart != -1 && phoneStart != -1) {
NRIC = input.substring(nricStart + 3, phoneStart).trim();
nric = input.substring(nricStart + 3, phoneStart).trim();
} else if (nricStart != -1) { // Handle case where there is no phone number
NRIC = input.substring(nricStart + 3).trim();
nric = input.substring(nricStart + 3).trim();
}

// Extract phone number
Expand Down Expand Up @@ -115,15 +116,15 @@ public void add(String input, Records records) {
dateOfBirth = input.substring(dobStart + 4).trim();
}

Patient patient = new Patient(name, NRIC);
Patient patient = new Patient(name, nric);
patient.setPhoneNumber(phoneNumber);
patient.setDiagnosis(diagnosis);
patient.setHomeAddress(homeAddress);
patient.setDateOfBirth(dateOfBirth);
patient.setMedication(medications);

records.addPatient(patient);
System.out.println("Patient " + name + " with NRIC " + NRIC + " added.");
System.out.println("Patient " + name + " with NRIC " + nric + " added.");
}

// Utility method to find the start of the next field or the end of the input string
Expand Down

0 comments on commit 77e873b

Please sign in to comment.