Skip to content

Commit

Permalink
Merge pull request #71 from vibes-863/69-delete-account-one-present
Browse files Browse the repository at this point in the history
69 delete account one present
  • Loading branch information
vibes-863 committed Apr 3, 2024
2 parents 2871edd + 1249133 commit b06a047
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/budgetbuddy/account/AccountManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public void removeAccount(String input, TransactionList transactions)
InvalidIndexException {
int accountNumber = Parser.parseRemoveAccount(input);
Account accountRemoved = getAccountByAccountNumber(accountNumber);
if (accounts.size() == 1) {
UserInterface.printCannotDeleteLastAccountMessage();
return;
}
accounts.remove(accountRemoved);
existingAccountNumbers.remove(Integer.valueOf(accountNumber));
ArrayList<Transaction> transactionsRemoved = transactions.removeTransactionsByAccountNumber(accountNumber);
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/budgetbuddy/ui/UserInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -455,5 +455,13 @@ public static void printUpdatedAccount(String account) {
}
System.out.println(LINE);
}

public static void printCannotDeleteLastAccountMessage() {
System.out.println(LINE);
System.out.println(TAB_SPACE + "You cannot delete the last account.");
System.out.println(TAB_SPACE + "Please edit the current account or add a new account before deleting " +
"this one.");
System.out.println(LINE);
}
//@@author
}

0 comments on commit b06a047

Please sign in to comment.