Skip to content

Commit

Permalink
Refactor Parser to standardize command formats
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmejr257 committed Mar 12, 2024
1 parent e05d809 commit 73491db
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/main/java/seedu/budgetbuddy/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ private String extractDetailsForAdd(String details, String prefix) {
int startIndex = details.indexOf(prefix) + prefix.length();
int endIndex = details.length();

String[] nextPrefixes = { "/c", "/a", "/d" };
String[] nextPrefixes = { "c/", "a/", "d/" };
for (String nextPrefix : nextPrefixes) {
if (details.indexOf(nextPrefix, startIndex) != -1 && details.indexOf(nextPrefix, startIndex) < endIndex) {
endIndex = details.indexOf(nextPrefix, startIndex);
Expand Down Expand Up @@ -56,9 +56,9 @@ public Command handleAddExpenseCommand(ExpenseList expenses, String input) {
String[] parts = input.split(" ", 2);
String details = parts[1];
try {
String category = extractDetailsForAdd(details, "/c");
String amount = extractDetailsForAdd(details, "/a");
String description = extractDetailsForAdd(details, "/d");
String category = extractDetailsForAdd(details, "c/");
String amount = extractDetailsForAdd(details, "a/");
String description = extractDetailsForAdd(details, "d/");
return new AddExpenseCommand(expenses,category, amount, description);
} catch (Exception e) {
System.out.println("Error parsing expense. Ensure the format is correct.");
Expand All @@ -73,8 +73,8 @@ public Command handleAddSavingCommand(SavingList savings, String input) {
String details = parts[1];

try {
String category = extractDetailsForAdd(details, "/c");
String amount = extractDetailsForAdd(details, "/a");
String category = extractDetailsForAdd(details, "c/");
String amount = extractDetailsForAdd(details, "a/");
return new AddSavingCommand(savings, category, amount);
} catch (Exception e) {
System.out.println("Error parsing saving. Ensure the format is correct.");
Expand Down

0 comments on commit 73491db

Please sign in to comment.