From 343609954eba4142842fc3b20fbe829c4fd68083 Mon Sep 17 00:00:00 2001 From: itsmejr257 Date: Sun, 14 Apr 2024 15:08:20 +0800 Subject: [PATCH 01/10] Add JavaDocs comments to Storage --- src/main/java/seedu/budgetbuddy/Storage.java | 27 +++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/main/java/seedu/budgetbuddy/Storage.java b/src/main/java/seedu/budgetbuddy/Storage.java index 649c3f8cf4..549e9af124 100644 --- a/src/main/java/seedu/budgetbuddy/Storage.java +++ b/src/main/java/seedu/budgetbuddy/Storage.java @@ -29,6 +29,7 @@ public class Storage { private static final Logger LOGGER = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); + private static final double MAX_AMOUNT = 1_000_000_000_000.00; private final String filePath; private ArrayList expenseCategories = new ArrayList<>(Arrays.asList("Housing" @@ -52,23 +53,41 @@ private void ensureDirectoryExists() { } private void checkValidAmount(Double amount) throws BudgetBuddyException{ - if (amount <= 0) { + if (amount <= 0 || amount > MAX_AMOUNT) { throw new BudgetBuddyException("Invalid Amount detected. Possible Corrupted File"); } } + /** + * Checks if the provided category is a valid category + * + * @param category The category to be checked + * @throws BudgetBuddyException If category does not match any of the expense categories exactly + */ private void checkValidCategory(String category) throws BudgetBuddyException { if (!expenseCategories.contains(category)) { throw new BudgetBuddyException("Invalid Category detected. Possible Corrupted File"); } } + /** + * Checks for the presence of the `!`, `|`, or empty string in the description + * + * @param description The description to be checked + * @throws BudgetBuddyException If the description contains a `|`, `!` or is empty + */ private void checkValidDescription(String description) throws BudgetBuddyException { if (description.contains("|") || description.contains("!") || description.isEmpty()) { throw new BudgetBuddyException("Invalid description detected. Possible Corrupted File"); } } + /** + * Checks for the proper format for the title of the recurring expense list. + * + * @param line The line to be checked + * @throws BudgetBuddyException If the end `!!!` is not found at the end of the line + */ private void checkValidTitle(String line) throws BudgetBuddyException { int indexOfEndExclamation = line.indexOf("!!!", 4); int endIndexOfEndExclamation = indexOfEndExclamation + "!!!".length(); @@ -78,6 +97,12 @@ private void checkValidTitle(String line) throws BudgetBuddyException { } } + /** + * Checks for the presence of the `!`, `|`, or empty string in the provided `listName` + * + * @param listName The description to be checked + * @throws BudgetBuddyException If the `listName` contains a `|`, `!` or is empty + */ private void checkValidListName(String listName) throws BudgetBuddyException { if (listName.contains("!") || listName.contains("|") || listName.isEmpty()) { throw new BudgetBuddyException("Invalid listName detected. Possible Corrupted File"); From fda7198b48c1459389283d4e9670983f7696aacb Mon Sep 17 00:00:00 2001 From: itsmejr257 Date: Sun, 14 Apr 2024 15:08:53 +0800 Subject: [PATCH 02/10] Update menu ordering and confirmation messages in Ui --- src/main/java/seedu/budgetbuddy/Ui.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/seedu/budgetbuddy/Ui.java b/src/main/java/seedu/budgetbuddy/Ui.java index e835f336a0..057d1f2c95 100644 --- a/src/main/java/seedu/budgetbuddy/Ui.java +++ b/src/main/java/seedu/budgetbuddy/Ui.java @@ -14,7 +14,7 @@ public void showWelcome() { System.out.println("To view all menu items again, type \"menu\"."); System.out.println(DIVIDER); System.out.println("0. Display the whole menu"); - System.out.println("1. Manage Expenses 2. View Expenses"); + System.out.println("1. Manage Expenses 2. Manage Savings"); System.out.println("3. View Expenses 4. View Savings"); System.out.println("5. Find Expenses 6. Divide Bills"); System.out.println("7. Manage Recurring Bills 8. Change Currency"); @@ -33,8 +33,8 @@ public void showMenuTitles() { System.out.println(DIVIDER); System.out.println("Menu Options:"); System.out.println("0. Display the whole menu"); - System.out.println("1. Manage Expenses 3. View Expenses"); - System.out.println("2. Manage Savings 4. View Savings"); + System.out.println("1. Manage Expenses 2. Manage Savings"); + System.out.println("3. View Expenses 4. View Savings"); System.out.println("5. Find Expenses 6. Divide Bills"); System.out.println("7. Manage Recurring Bills 8. Change Currency"); System.out.println("9. Manage Budget 10. Get Graphical Insights"); @@ -45,7 +45,8 @@ public void showMenuTitles() { // Method to get user confirmation from the console public boolean getUserConfirmation() { Scanner scanner = new Scanner(System.in); - System.out.println("Do you want to proceed with adding this expense? (yes/no)"); + System.out.println("Do you want to proceed with adding this expense? (Any input that " + + "is not 'yes' is treated as a no)"); String userInput = scanner.nextLine().trim().toLowerCase(); return userInput.equals("yes"); } From 1b6cbe68013125b0b63b4dee4f56da78d055ddaa Mon Sep 17 00:00:00 2001 From: itsmejr257 Date: Sun, 14 Apr 2024 15:09:23 +0800 Subject: [PATCH 03/10] Refector RecurringExpenseCommand to work with Budget --- .../command/RecurringExpenseCommand.java | 38 +++++++++---------- .../RecurringExpenseCommandCreator.java | 35 ++++++++++++++++- .../budgetbuddy/commons/ExpenseList.java | 31 +++++++++++++++ 3 files changed, 81 insertions(+), 23 deletions(-) diff --git a/src/main/java/seedu/budgetbuddy/command/RecurringExpenseCommand.java b/src/main/java/seedu/budgetbuddy/command/RecurringExpenseCommand.java index ed77c0de5d..43873b5ec3 100644 --- a/src/main/java/seedu/budgetbuddy/command/RecurringExpenseCommand.java +++ b/src/main/java/seedu/budgetbuddy/command/RecurringExpenseCommand.java @@ -11,7 +11,6 @@ import java.util.logging.Logger; public class RecurringExpenseCommand extends Command{ - private static final Logger LOGGER = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); private RecurringExpenseLists recurringExpenseLists; private ExpenseList overallExpenses; @@ -156,23 +155,17 @@ private void addExpenseToList(int listNumber, String category, Double amount, St ExpenseList expenses = recurringExpenseLists.getExpenseListAtListNumber(listNumber); - try { - expenses.addExpense(category, amount.toString(), description); + Expense expenseToAdd = new Expense(category, amount, description); + expenses.getExpenses().add(expenseToAdd); - ui.printDivider(); - System.out.println("Successfully Added Expense to " + expenses.getName()); - System.out.println("|Details of Expense"); - System.out.println("--------------------"); - System.out.println("|Category : " + category); - System.out.println("|Amount : " + String.format("%.2f", amount)); - System.out.println("|Description : " + description); - ui.printDivider(); - - } catch (BudgetBuddyException e) { - LOGGER.log(Level.WARNING - , "An attempt to add an Invalid Expense was created. Error Captured Successfully"); - System.out.println(e.getMessage()); - } + ui.printDivider(); + System.out.println("Successfully Added Expense to " + expenses.getName()); + System.out.println("|Details of Expense"); + System.out.println("--------------------"); + System.out.println("|Category : " + category); + System.out.println("|Amount : " + String.format("%.2f", amount)); + System.out.println("|Description : " + description); + ui.printDivider(); } @@ -208,14 +201,15 @@ private void addRecurringExpensesToExpenses(int listNumber, RecurringExpenseList Double amount = expense.getAmount(); String description = expense.getDescription(); - Command addExpenseCommand = new AddExpenseCommand(overallExpenses, category, - amount.toString(), description); + ui.printDivider(); + System.out.println("Adding : " + category + " | " + amount + " | " + description + " | "); - addExpenseCommand.execute(); + overallExpenses.addExpense(category,amount,description); + ui.printDivider(); } ui.printDivider(); - System.out.println("Your Recurring Expenses in " + expenseList.getName() + + System.out.println("Your chosen Recurring Expenses in " + expenseList.getName() + " has been added to your overall Expenses"); ui.printDivider(); @@ -229,6 +223,7 @@ private void addRecurringExpensesToExpenses(int listNumber, RecurringExpenseList * @param recurringExpenseLists The recurringExpensesList to obtain ExpenseList from */ private void printExpensesAtIndex(int listNumber, RecurringExpenseLists recurringExpenseLists) { + assert recurringExpenseLists != null : "listNumber cannot be Null"; if (listNumber <= 0 || listNumber > recurringExpenseLists.getSize()) { System.out.println("Invalid List Number. Choose a List Number from 1 onwards"); @@ -249,6 +244,7 @@ private void printList() { recurringExpenseLists.printAllRecurringLists(); } public void execute(){ + assert commandType != null : "CommandType cannot be null"; switch(commandType) { case "newlist": diff --git a/src/main/java/seedu/budgetbuddy/commandcreator/RecurringExpenseCommandCreator.java b/src/main/java/seedu/budgetbuddy/commandcreator/RecurringExpenseCommandCreator.java index be41528409..f3c720c5ee 100644 --- a/src/main/java/seedu/budgetbuddy/commandcreator/RecurringExpenseCommandCreator.java +++ b/src/main/java/seedu/budgetbuddy/commandcreator/RecurringExpenseCommandCreator.java @@ -6,11 +6,14 @@ import seedu.budgetbuddy.command.RecurringExpenseCommand; import seedu.budgetbuddy.exception.BudgetBuddyException; +import java.util.ArrayList; +import java.util.Arrays; import java.util.logging.Level; import java.util.logging.Logger; public class RecurringExpenseCommandCreator extends CommandCreator{ private static final Logger LOGGER = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); + private static final double MAX_AMOUNT = 1_000_000_000_000.00; private static final String LISTNUMBER_PREFIX = "to/"; private static final String CATEGORY_PREFIX = "c/"; private static final String AMOUNT_PREFIX = "a/"; @@ -19,6 +22,9 @@ public class RecurringExpenseCommandCreator extends CommandCreator{ private RecurringExpenseLists recurringExpenseLists; private ExpenseList expenses; + private ArrayList expenseCategories = new ArrayList<>(Arrays.asList("Housing" + , "Groceries", "Utility", "Transport", "Entertainment", "Others")); + /** * Constructs a RecurringExpenseCommandCreator with the provided input, recurringExpensesList and expenses @@ -161,9 +167,30 @@ private Double parseAmount(String input) throws NumberFormatException, BudgetBud Double amount = Double.parseDouble(amountAsString); + if(amount > MAX_AMOUNT) { + throw new BudgetBuddyException("Please Ensure that Amount is Less than " + "1,000,000,000,000"); + } + return amount; } + + /** + * Returns a case-insensitive match to the provided `category` + * @param category The category to be found + * @return The case-insensitive match to the category to be found + * @throws BudgetBuddyException if no matches are found + */ + private String getCategory(String category) throws BudgetBuddyException{ + for (String validCategory : expenseCategories) { + if (validCategory.equalsIgnoreCase(category)) { + return validCategory; + } + } + + throw new BudgetBuddyException("Please ensure the category is a valid category\n" + + "Valid Categories : Entertainment, Housing, Groceries, Utility, Transport, Other"); + } /** * Parses the category from the input string * @@ -178,12 +205,14 @@ private String parseCategory(String input) throws BudgetBuddyException{ int indexOfAmountPrefix = input.indexOf(AMOUNT_PREFIX); int endIndexOfCategory = indexOfAmountPrefix; - String category = input.substring(startIndexOfCategory, endIndexOfCategory).trim(); + String categoryToObtain = input.substring(startIndexOfCategory, endIndexOfCategory).trim(); - if(category.trim().isEmpty()) { + if(categoryToObtain.trim().isEmpty()) { + LOGGER.log(Level.WARNING, "Empty Category Detected, throwing BudgetBuddyException"); throw new BudgetBuddyException("Please Ensure Category is NOT empty"); } + String category = getCategory(categoryToObtain); return category; } @@ -205,6 +234,7 @@ private int parseListNumber(String input) throws NumberFormatException, BudgetBu String listNumberAsString = input.substring(startIndexOfListNumber, endIndexOfListNumber).trim(); if(listNumberAsString.trim().isEmpty()) { + LOGGER.log(Level.WARNING, "Empty ListNumber Detected, throwing BudgetBuddyException"); throw new BudgetBuddyException("Please Ensure List Number is NOT empty"); } @@ -246,6 +276,7 @@ private void checkForDuplicateParameters(String input) throws BudgetBuddyExcepti for (String parameter : parameters) { if (input.indexOf(parameter) != input.lastIndexOf(parameter)) { + LOGGER.log(Level.WARNING, "Duplicate Parameters Detected, throwing BudgetBuddyException"); throw new BudgetBuddyException("Please ensure that you do not have any duplicate parameters"); } } diff --git a/src/main/java/seedu/budgetbuddy/commons/ExpenseList.java b/src/main/java/seedu/budgetbuddy/commons/ExpenseList.java index b4d0323330..586c946511 100644 --- a/src/main/java/seedu/budgetbuddy/commons/ExpenseList.java +++ b/src/main/java/seedu/budgetbuddy/commons/ExpenseList.java @@ -170,6 +170,37 @@ private boolean checkBudgetBeforeAddingExpense(String category, double amountAsD return false; } + //@@author itsmejr257 + + /** + * Adds an expense to the overall expense list. Takes in 2 strings, category and description, and one double + * value. This method assumes that the provide category, amount and description is always valid + * + * @param category The category of the expense to be added + * @param amount The amount of the expense to be added + * @param description The description of the expense to be added + */ + public void addExpense(String category, Double amount, String description) { + assert category != null : "Category should not be null"; + assert amount != null : "Amount should not be null"; + assert description != null : "Description should not be null"; + + boolean budgetExceeded = checkBudgetBeforeAddingExpense(category, amount); + if (budgetExceeded) { + System.out.println("Warning: Adding this expense will exceed your budget for " + category); + boolean userConfirmation = ui.getUserConfirmation(); + if (!userConfirmation) { + System.out.println("Expense not added due to budget constraints."); + return; + } + } + + Expense expense = new Expense(category, amount, description); + expenses.add(expense); + + System.out.println("Expense added: " + category + " of $" + String.format("%.2f", amount) + + " Description: " + description); + } //@@author Zhang Yangda From 060084a3e55145f019fb0cae911811922a140026 Mon Sep 17 00:00:00 2001 From: itsmejr257 Date: Sun, 14 Apr 2024 15:55:32 +0800 Subject: [PATCH 04/10] Refactor parser to standardize use of createCommand --- src/main/java/seedu/budgetbuddy/Parser.java | 82 +++++++-------------- 1 file changed, 27 insertions(+), 55 deletions(-) diff --git a/src/main/java/seedu/budgetbuddy/Parser.java b/src/main/java/seedu/budgetbuddy/Parser.java index a074a61723..c7aac9453f 100644 --- a/src/main/java/seedu/budgetbuddy/Parser.java +++ b/src/main/java/seedu/budgetbuddy/Parser.java @@ -172,101 +172,73 @@ public Boolean isGetSavingsInsightsCommand(String input) { */ public Command parseCommand(ExpenseList expenses, SavingList savings, SplitExpenseList splitexpenses, RecurringExpenseLists expensesList, String input) { - + + CommandCreator commandCreator = null; + if(isMenuCommand(input)) { LOGGER.log(Level.INFO, "Confirmed that input is a menu command"); - CommandCreator commandCreator = new MenuCommandCreator(input); - return commandCreator.createCommand(); + commandCreator = new MenuCommandCreator(input); } - if (isAddExpenseCommand(input)) { - CommandCreator commandCreator = new AddExpenseCommandCreator(expenses, input); - return commandCreator.createCommand(); + commandCreator = new AddExpenseCommandCreator(expenses, input); } - if (isAddSavingCommand(input)) { - CommandCreator commandCreator = new AddSavingCommandCreator(savings, input); - return commandCreator.createCommand(); + commandCreator = new AddSavingCommandCreator(savings, input); } - if (isEditExpenseCommand(input)) { - CommandCreator commandCreator = new EditExpenseCommandCreator(input, expenses); - return commandCreator.createCommand(); + commandCreator = new EditExpenseCommandCreator(input, expenses); } - if (isEditSavingCommand(input)) { - CommandCreator commandCreator = new EditSavingsCommandCreator(input, savings); - return commandCreator.createCommand(); + commandCreator = new EditSavingsCommandCreator(input, savings); } - if (isDeleteExpenseCommand(input)) { - CommandCreator commandCreator = new DeleteExpenseCommandCreator(expenses, input); - return commandCreator.createCommand(); + commandCreator = new DeleteExpenseCommandCreator(expenses, input); } - if (isReduceSavingCommand(input)) { - CommandCreator commandCreator = new ReduceSavingCommandCreator(savings, input); - return commandCreator.createCommand(); + commandCreator = new ReduceSavingCommandCreator(savings, input); } - if (isListCommand(input.toLowerCase())) { - CommandCreator commandCreator = new ListCommandCreator(expenses, savings, input); - return commandCreator.createCommand(); + commandCreator = new ListCommandCreator(expenses, savings, input); } - if (isListSplitExpenseCommand(input)) { - CommandCreator commandCreator = new ListSplittedExpenseCommandCreator(input, splitexpenses); - return commandCreator.createCommand(); + commandCreator = new ListSplittedExpenseCommandCreator(input, splitexpenses); } - if (isFindExpensesCommand(input)) { - CommandCreator commandCreator = new FindExpensesCommandCreator(input, expenses); - return commandCreator.createCommand(); + commandCreator = new FindExpensesCommandCreator(input, expenses); } - if (isRecCommand(input)) { - CommandCreator commandCreator = new RecurringExpenseCommandCreator(input, expensesList, expenses); - return commandCreator.createCommand(); + commandCreator = new RecurringExpenseCommandCreator(input, expensesList, expenses); } - if (isConvertCurrencyCommand(input.toLowerCase())) { - CommandCreator commandCreator = new ChangeCurrencyCommandCreator(input, savings, expenses, splitexpenses, + commandCreator = new ChangeCurrencyCommandCreator(input, savings, expenses, splitexpenses, expensesList, new CurrencyConverter()); - return commandCreator.createCommand(); } - if (isSplitExpenseCommand(input)) { - CommandCreator commandCreator = new SplitExpenseCommandCreator(splitexpenses, input); - return commandCreator.createCommand(); + commandCreator = new SplitExpenseCommandCreator(splitexpenses, input); } - if (isSettleSplitExpenseCommand(input)) { - CommandCreator commandCreator = new SettleSplitExpenseCommandCreator(input, splitexpenses); - return commandCreator.createCommand(); + commandCreator = new SettleSplitExpenseCommandCreator(input, splitexpenses); } - if (isSetBudgetCommand(input)) { - CommandCreator commandCreator = new SetBudgetCommandCreator(expenses, input); - return commandCreator.createCommand(); + commandCreator = new SetBudgetCommandCreator(expenses, input); } if (isGetBudgetCommand(input)) { - CommandCreator commandCreator = new GetBudgetCommandCreator(expenses, input); - return commandCreator.createCommand(); + commandCreator = new GetBudgetCommandCreator(expenses, input); } if (isListBudgetCommand(input)){ - CommandCreator commandCreator = new ListBudgetCommandCreator(expenses); - return commandCreator.createCommand(); + commandCreator = new ListBudgetCommandCreator(expenses); } if (isGetExpensesInsightsCommand(input)) { - CommandCreator commandCreator = new GetExpenseInsightsCommandCreator(expenses); - return commandCreator.createCommand(); + commandCreator = new GetExpenseInsightsCommandCreator(expenses); } - if (isGetSavingsInsightsCommand(input)) { - CommandCreator commandCreator = new GetSavingsInsightsCommandCreator(savings); - return commandCreator.createCommand(); + commandCreator = new GetSavingsInsightsCommandCreator(savings); + } + + if (commandCreator == null) { + return null; } - return null; + return commandCreator.createCommand(); } } From 82e1736e231427b8f69123175d47a7667c96b85e Mon Sep 17 00:00:00 2001 From: itsmejr257 Date: Sun, 14 Apr 2024 15:55:56 +0800 Subject: [PATCH 05/10] Move JUnit test to correct test file --- .../RecurringExpenseCommandCreatorTest.java | 20 ++++++++++++++++++- .../RecurringExpenseCommandTest.java | 15 -------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/test/java/seedu/budgetbuddy/RecurringExpenseCommandCreatorTest.java b/src/test/java/seedu/budgetbuddy/RecurringExpenseCommandCreatorTest.java index 772e15f02d..08e5e7aeac 100644 --- a/src/test/java/seedu/budgetbuddy/RecurringExpenseCommandCreatorTest.java +++ b/src/test/java/seedu/budgetbuddy/RecurringExpenseCommandCreatorTest.java @@ -8,9 +8,9 @@ import seedu.budgetbuddy.commons.ExpenseList; import seedu.budgetbuddy.commons.RecurringExpenseLists; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertInstanceOf; -import static org.junit.jupiter.api.Assertions.assertNull; public class RecurringExpenseCommandCreatorTest { @@ -268,4 +268,22 @@ public void handleRecCommand_newExpenseToListCommandWithEmptyListNumber_returnsN assertNull(command); } + @Test + public void handleRecCommand_newExpenseToListCommandWithInvalidCategory_returnsNull() { + + RecurringExpenseLists recurringExpenseLists = new RecurringExpenseLists(); + ExpenseList expenseList = new ExpenseList(); + recurringExpenseLists.addNewRecurringList("list1"); + + String userInput = "rec newexpense to/1 c/invalid a/500 d/description"; + + RecurringExpenseCommandCreator recurringExpenseCommandCreator = new RecurringExpenseCommandCreator(userInput + , recurringExpenseLists,expenseList); + + Command newExpenseCommand = recurringExpenseCommandCreator.createCommand(); + + assertNull(newExpenseCommand); + + } + } diff --git a/src/test/java/seedu/budgetbuddy/RecurringExpenseCommandTest.java b/src/test/java/seedu/budgetbuddy/RecurringExpenseCommandTest.java index 67cd1f7cf5..9feb91a9bd 100644 --- a/src/test/java/seedu/budgetbuddy/RecurringExpenseCommandTest.java +++ b/src/test/java/seedu/budgetbuddy/RecurringExpenseCommandTest.java @@ -157,21 +157,6 @@ public void execute_removeListWithOutOfBoundsListNumber_sizeOfOverallListStaysSa assertEquals(3, recurringExpenseLists.getSize()); } - @Test - public void execute_newExpenseCommandWithInvalidCategory_sizeOfRecurringExpenseListUnchanged() { - - RecurringExpenseLists recurringExpenseLists = new RecurringExpenseLists(); - recurringExpenseLists.addNewRecurringList("list1"); - - RecurringExpenseCommand newExpenseCommand = new RecurringExpenseCommand(1, recurringExpenseLists - ,"invalid", 500.00,"description", "newexpense" ); - - - newExpenseCommand.execute(); - - assertEquals(0, recurringExpenseLists.getExpenseListAtListNumber(1).getExpenses().size()); - - } @Test public void execute_newExpenseCommand_sizeOfRecurringExpenseListIncreaseByOne() { From e5995cd52cd1ffebb7b3de72b0ec13053a6f12a0 Mon Sep 17 00:00:00 2001 From: itsmejr257 Date: Sun, 14 Apr 2024 15:56:21 +0800 Subject: [PATCH 06/10] Add error handling for negative amounts --- .../commandcreator/RecurringExpenseCommandCreator.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/budgetbuddy/commandcreator/RecurringExpenseCommandCreator.java b/src/main/java/seedu/budgetbuddy/commandcreator/RecurringExpenseCommandCreator.java index f3c720c5ee..5298f2b155 100644 --- a/src/main/java/seedu/budgetbuddy/commandcreator/RecurringExpenseCommandCreator.java +++ b/src/main/java/seedu/budgetbuddy/commandcreator/RecurringExpenseCommandCreator.java @@ -167,8 +167,9 @@ private Double parseAmount(String input) throws NumberFormatException, BudgetBud Double amount = Double.parseDouble(amountAsString); - if(amount > MAX_AMOUNT) { - throw new BudgetBuddyException("Please Ensure that Amount is Less than " + "1,000,000,000,000"); + if(amount > MAX_AMOUNT || amount <= 0) { + throw new BudgetBuddyException("Please Ensure that Amount is a positive integer (Not 0) and is Less than " + + "1,000,000,000,000"); } return amount; From c7d7ae5ccab272655ff7ebb56dfeb6cbd7ef9c2a Mon Sep 17 00:00:00 2001 From: itsmejr257 Date: Sun, 14 Apr 2024 15:56:36 +0800 Subject: [PATCH 07/10] Remove unused imports in Recurring Expense Command --- .../seedu/budgetbuddy/command/RecurringExpenseCommand.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/seedu/budgetbuddy/command/RecurringExpenseCommand.java b/src/main/java/seedu/budgetbuddy/command/RecurringExpenseCommand.java index 43873b5ec3..79f669be47 100644 --- a/src/main/java/seedu/budgetbuddy/command/RecurringExpenseCommand.java +++ b/src/main/java/seedu/budgetbuddy/command/RecurringExpenseCommand.java @@ -4,11 +4,8 @@ import seedu.budgetbuddy.commons.ExpenseList; import seedu.budgetbuddy.commons.RecurringExpenseLists; import seedu.budgetbuddy.Ui; -import seedu.budgetbuddy.exception.BudgetBuddyException; import java.util.ArrayList; -import java.util.logging.Level; -import java.util.logging.Logger; public class RecurringExpenseCommand extends Command{ private RecurringExpenseLists recurringExpenseLists; From 3cd8d3c3fca5ee6ac1ac32ecb913bd81be512ec2 Mon Sep 17 00:00:00 2001 From: itsmejr257 Date: Sun, 14 Apr 2024 15:57:13 +0800 Subject: [PATCH 08/10] Add details to JavaDoc comments for overloaded addExpense method --- src/main/java/seedu/budgetbuddy/commons/ExpenseList.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/budgetbuddy/commons/ExpenseList.java b/src/main/java/seedu/budgetbuddy/commons/ExpenseList.java index 586c946511..83e3ae7712 100644 --- a/src/main/java/seedu/budgetbuddy/commons/ExpenseList.java +++ b/src/main/java/seedu/budgetbuddy/commons/ExpenseList.java @@ -171,10 +171,11 @@ private boolean checkBudgetBeforeAddingExpense(String category, double amountAsD } //@@author itsmejr257 - /** * Adds an expense to the overall expense list. Takes in 2 strings, category and description, and one double - * value. This method assumes that the provide category, amount and description is always valid + * value. + * This method is an overloaded method, where this method takes in an amount as a Double attribute and + * assumes that the provide category, amount and description is always valid. * * @param category The category of the expense to be added * @param amount The amount of the expense to be added From f56187c7891b7c3a81450903a1651dd2604ce41a Mon Sep 17 00:00:00 2001 From: itsmejr257 Date: Sun, 14 Apr 2024 16:06:02 +0800 Subject: [PATCH 09/10] Add author tags to methods --- src/main/java/seedu/budgetbuddy/Storage.java | 5 ++++- .../java/seedu/budgetbuddy/commons/CurrencyConverter.java | 5 ++++- src/main/java/seedu/budgetbuddy/commons/ExpenseList.java | 4 +++- .../java/seedu/budgetbuddy/commons/RecurringExpenseList.java | 2 +- .../seedu/budgetbuddy/commons/RecurringExpenseLists.java | 1 + 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/seedu/budgetbuddy/Storage.java b/src/main/java/seedu/budgetbuddy/Storage.java index 549e9af124..665be68cf1 100644 --- a/src/main/java/seedu/budgetbuddy/Storage.java +++ b/src/main/java/seedu/budgetbuddy/Storage.java @@ -263,6 +263,7 @@ public void resetSavingsListFile() throws IOException { writer.close(); } + // @@author itsmejr257 /** * Deletes the existing recurring expenses file and create a new, empty file. * This method is used to reset the recurring expenses file when it has been detected to be corrupted @@ -409,7 +410,9 @@ public void saveRecurringExpenses(RecurringExpenseLists recurringExpenseLists) ", file has been reinitialized. Run a command to save your recurringexpenses"); } - } + } + // @@author + /** * Saves the default currency to the specified file path. diff --git a/src/main/java/seedu/budgetbuddy/commons/CurrencyConverter.java b/src/main/java/seedu/budgetbuddy/commons/CurrencyConverter.java index f7b4fd999e..31dbc9c65b 100644 --- a/src/main/java/seedu/budgetbuddy/commons/CurrencyConverter.java +++ b/src/main/java/seedu/budgetbuddy/commons/CurrencyConverter.java @@ -180,6 +180,7 @@ public void convertSavingCurrency(Currency newCurrency, SavingList savings) { } } + // @@author itsmejr257 public void convertRecurringExpensesCurrency(Currency newCurrency, RecurringExpenseLists recurringExpenseLists) { assert recurringExpenseLists != null : "RecurringExpenseLists cannot be null"; @@ -203,7 +204,9 @@ public void convertRecurringExpensesCurrency(Currency newCurrency, RecurringExpe System.out.println("Default currency for Recurring Expenses changed to " + newCurrency); ui.printDivider(); } - + // @@author + + public void convertBudgetCurrency(Currency newCurrency, ExpenseList expenseList) { if (expenseList == null) { throw new IllegalArgumentException("ExpenseList cannot be null"); diff --git a/src/main/java/seedu/budgetbuddy/commons/ExpenseList.java b/src/main/java/seedu/budgetbuddy/commons/ExpenseList.java index 83e3ae7712..642cf812e1 100644 --- a/src/main/java/seedu/budgetbuddy/commons/ExpenseList.java +++ b/src/main/java/seedu/budgetbuddy/commons/ExpenseList.java @@ -53,6 +53,7 @@ public List getBudgets() { } + // @@author itsmejr257 /** * Filters this.expenses based on the provided description, minimum amount and maximum amount. * This method uses Java streams to perform a case-insensitive search for the description @@ -84,6 +85,7 @@ public ArrayList filterExpenses(String description, Double minAmount, D return filteredExpenses; } + // @@author /** * Lists expenses based on the provided filter category. @@ -202,7 +204,7 @@ public void addExpense(String category, Double amount, String description) { System.out.println("Expense added: " + category + " of $" + String.format("%.2f", amount) + " Description: " + description); } - + // @@author //@@author Zhang Yangda public void addExpense(String category, String amount, String description) throws BudgetBuddyException { diff --git a/src/main/java/seedu/budgetbuddy/commons/RecurringExpenseList.java b/src/main/java/seedu/budgetbuddy/commons/RecurringExpenseList.java index 5ee70e91fe..f749c461d3 100644 --- a/src/main/java/seedu/budgetbuddy/commons/RecurringExpenseList.java +++ b/src/main/java/seedu/budgetbuddy/commons/RecurringExpenseList.java @@ -2,7 +2,7 @@ import java.util.ArrayList; - +// @@author itsmejr257 /** * Represents a list of expenses for recurring expenses. This class extends * the ExpenseList class. diff --git a/src/main/java/seedu/budgetbuddy/commons/RecurringExpenseLists.java b/src/main/java/seedu/budgetbuddy/commons/RecurringExpenseLists.java index 0506e99af0..4765186d2e 100644 --- a/src/main/java/seedu/budgetbuddy/commons/RecurringExpenseLists.java +++ b/src/main/java/seedu/budgetbuddy/commons/RecurringExpenseLists.java @@ -4,6 +4,7 @@ import java.util.ArrayList; +// @@author itsmejr257 /** * Represents a list of ExpenseList. Each ExpenseList contains multiple expenses. * This class provides methods to add, remove and manage the list of ExpenseList From 99e3bdc130814302983cb2e74a75f805b9e64bd9 Mon Sep 17 00:00:00 2001 From: itsmejr257 Date: Sun, 14 Apr 2024 16:09:47 +0800 Subject: [PATCH 10/10] Update EXPECTED.TXT to match new menu layout --- text-ui-test/EXPECTED.TXT | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 40742e9466..7c5b8ac6a8 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -5,7 +5,7 @@ Welcome to BudgetBuddy, to start, please type "menu INDEX" to view commands for To view all menu items again, type "menu". __________________________________________________ 0. Display the whole menu -1. Manage Expenses 2. View Expenses +1. Manage Expenses 2. Manage Savings 3. View Expenses 4. View Savings 5. Find Expenses 6. Divide Bills 7. Manage Recurring Bills 8. Change Currency