Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Bug-Fixes and Relevant Documentation to RecurringExpenses and Menu Feature #230

Merged
82 changes: 27 additions & 55 deletions src/main/java/seedu/budgetbuddy/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
32 changes: 30 additions & 2 deletions src/main/java/seedu/budgetbuddy/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> expenseCategories = new ArrayList<>(Arrays.asList("Housing"
Expand All @@ -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();
Expand All @@ -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");
Expand Down Expand Up @@ -238,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
Expand Down Expand Up @@ -384,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.
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/seedu/budgetbuddy/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@
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 static final Logger LOGGER = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
private RecurringExpenseLists recurringExpenseLists;

private ExpenseList overallExpenses;
Expand Down Expand Up @@ -156,23 +152,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();

}

Expand Down Expand Up @@ -208,14 +198,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();

Expand All @@ -229,6 +220,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");
Expand All @@ -249,6 +241,7 @@ private void printList() {
recurringExpenseLists.printAllRecurringLists();
}
public void execute(){
assert commandType != null : "CommandType cannot be null";

switch(commandType) {
case "newlist":
Expand Down
Loading
Loading