diff --git a/src/main/java/budgetbuddy/parser/Parser.java b/src/main/java/budgetbuddy/parser/Parser.java index 3e94f8b803..b0c64057fd 100644 --- a/src/main/java/budgetbuddy/parser/Parser.java +++ b/src/main/java/budgetbuddy/parser/Parser.java @@ -15,12 +15,22 @@ import budgetbuddy.transaction.type.Transaction; import budgetbuddy.ui.UserInterface; +/** + * Parses the user input into data that is easily understandable by other classes and methods. + */ public class Parser { public static final int ADD_COMMAND_INDEX = 3; public static final int HELP_BEGIN_INDEX = 4; private static final int ADD_ACC_COMMAND_INDEX = 7; + /** + * The function `parseAccountNumber` extracts and returns an account number from a given input + * string following a specific syntax. + * + * @param input The input string that contains the account number to be parsed. + * @return The method is returning an integer value, which is the account number parsed from the input string. + */ public static int parseAccountNumber(String input) throws InvalidArgumentSyntaxException { String data = input.substring(ADD_COMMAND_INDEX + 1); String[] parseData = data.split("/"); @@ -32,6 +42,15 @@ public static int parseAccountNumber(String input) throws InvalidArgumentSyntaxE throw new InvalidArgumentSyntaxException("Invalid add syntax."); } + /** + * The function `parseUserInputToTransaction` takes user input, parses it to create a transaction + * object (either income or expense), and handles various exceptions related to invalid input. + * + * @param input takes a user input that contain transaction details in a specific format. + * @param account The `account` parameter in this method represents the account to which the transaction belongs. + * @return The method `parseUserInputToTransaction` is returning a `Transaction` object, which can + * be either an `Income` or an `Expense` object based on the type provided in the input. + */ public Transaction parseUserInputToTransaction(String input, Account account) throws InvalidTransactionTypeException, NumberFormatException, EmptyArgumentException, InvalidCategoryException, InvalidAddTransactionSyntax { @@ -102,6 +121,17 @@ public Transaction parseUserInputToTransaction(String input, Account account) } //@@author Vavinan + /** + * The `parseEditTransaction` function in Java parses a new transaction string and creates either + * an Income or Expense object based on the transaction type, validating the category number and + * throwing exceptions for invalid data. + * + * @param newTransaction The `newTransaction` string is expected to be in a specific format + * @param account The `account` parameter in the `parseEditTransaction` method represents the + * account to which the transaction belongs. + * @return The `parseEditTransaction` method is returning a `Transaction` object, which can be + * either an `Income` or `Expense` object based on the type provided in the `newTransaction` string. + */ public Transaction parseEditTransaction(String newTransaction, Account account) throws InvalidEditTransactionData, InvalidCategoryException { String[] parts = newTransaction.split(" \\| "); @@ -135,6 +165,13 @@ public String parseHelpCommand(String input) { } //@@author + /** + * The `parseAddAccount` function in Java parses the input and returns the account name and + * balance of the new account that is to added. + * + * @param input It contains details about account name and initial balance + * @return A string array that contains the account name and initial balance + */ public static String[] parseAddAccount(String input) throws NumberFormatException, EmptyArgumentException { String data = input.substring(ADD_ACC_COMMAND_INDEX + 1).trim(); String[] parseData = data.split("/"); @@ -163,6 +200,12 @@ public static String[] parseAddAccount(String input) throws NumberFormatExceptio return new String[]{name, initialBalance}; } + /** + * The `parseRemoveAccount` function in Java parses the input and returns the account + * number that is to be deleted + * @param input It contains details about account number that is to be deleted + * @return A integer value representing the account number + */ public static int parseRemoveAccount(String input) throws NumberFormatException, EmptyArgumentException { if (input.trim().length() < 11) { @@ -175,7 +218,12 @@ public static int parseRemoveAccount(String input) return Integer.parseInt(data); } - + /** + * The `parseEditAccount` function in Java parses the input and returns the account + * number that is to be edited + * @param input It contains details about account number that is to be edited + * @return A integer value representing the account number + */ public static int parseEditAccount(String input) throws EmptyArgumentException { if (input.trim().length() < 9) { throw new EmptyArgumentException("edit-acc index "); diff --git a/src/main/java/budgetbuddy/ui/UserInterface.java b/src/main/java/budgetbuddy/ui/UserInterface.java index 2cfb491d6e..3b9bf87738 100644 --- a/src/main/java/budgetbuddy/ui/UserInterface.java +++ b/src/main/java/budgetbuddy/ui/UserInterface.java @@ -4,11 +4,14 @@ import budgetbuddy.categories.Category; import budgetbuddy.transaction.type.Transaction; - import java.time.LocalDate; import java.util.ArrayList; import java.util.Scanner; +/** + * Manages Overall interaction between users and the program. + * It handles all the input and output related tasks. + */ public class UserInterface { public static final int START_INDEX = 0; @@ -22,6 +25,11 @@ public class UserInterface { private static final String TAB_SPACE = " "; public static Scanner in = new Scanner(System.in); + /** + * The function `listCategories` prints out the available categories along with + * their corresponding + * category names and numbers. + */ public static void listCategories() { System.out.println(LINE); System.out.println(TAB_SPACE + "Here are the available categories:"); @@ -31,13 +39,34 @@ public static void listCategories() { System.out.println(LINE); } + /** + * The function prompts the user to enter a number between 1 and 9 to categorize + * a transaction and + * returns the input as an integer. + * + * @return The method `getCategoryNum()` returns an integer value representing + * the category number + * input by the user. + */ public static int getCategoryNum() { System.out.println("In which category do you want to list this transaction? [Enter number between 1 and 9]"); String input = in.nextLine(); return Integer.parseInt(input); } - + /** + * The function `printDeleteMessage` takes a transaction string and balance as + * input, splits the + * transaction string, and prints a message confirming the deletion of the + * transaction along with + * the updated account balance. + * + * @param transaction The `transaction` parameter is a string that contains + * information about a + * transaction, with different parts separated by the "|" + * character. + * @param balance The `balance` parameter represents the updated account + */ public static void printDeleteMessage(String transaction, double balance) { String[] parts = transaction.split("\\|"); System.out.println(LINE); @@ -50,6 +79,17 @@ public static void printDeleteMessage(String transaction, double balance) { } //@@author Vavinan + /** + * The function `printAddMessage` takes a transaction string and balance amount, + * formats and prints + * the transaction details along with the updated balance. + * + * @param transaction The `transaction` parameter is a string that contains + * information about a transaction. + * @param balance The `balance` parameter in the `printAddMessage` method + * represents the updated + * account balance after a transaction has been added. + */ public static void printAddMessage(String transaction, double balance) { String[] parts = transaction.split("\\|"); System.out.println(LINE); @@ -61,6 +101,18 @@ public static void printAddMessage(String transaction, double balance) { System.out.println(LINE); } + /** + * The function `printInvalidIndex` prints a message indicating an invalid index + * along with the + * valid index range. + * + * @param message The `message` parameter is a string that contains the error + * message to be + * displayed when an invalid index is provided. + * @param id The `id` parameter in the `printInvalidIndex` method + * represents the upper limit of the + * index range that is valid for the message being displayed. + */ public static void printInvalidIndex(String message, int id) { System.out.println(LINE); System.out.println(TAB_SPACE + message); @@ -68,6 +120,15 @@ public static void printInvalidIndex(String message, int id) { System.out.println(LINE); } + /** + * The function `printExceptionErrorMessage` prints an error message with a + * given message and + * provides guidance on checking command syntax. + * + * @param message The `message` parameter is a string that represents the error + * message associated + * with the exception that occurred. + */ public static void printExceptionErrorMessage(String message) { System.out.println(LINE); System.out.println(TAB_SPACE + "An error occurred with the message: " + message); @@ -76,12 +137,29 @@ public static void printExceptionErrorMessage(String message) { System.out.println(LINE); } + /** + * The function `printInvalidInput` prints an error message surrounded by a line + * to indicate + * invalid input. + * + * @param message The `message` parameter is a String that contains the error + * message to be displayed. + */ public static void printInvalidInput(String message) { System.out.println(LINE); System.out.println(TAB_SPACE + "Error occurred with message: " + message); System.out.println(LINE); } + /** + * The function `printInvalidAddSyntax` prints an error message along with a + * reminder to ensure + * correct argument entry. + * + * @param message The `message` parameter is a string that represents the error + * message to be displayed + * when the syntax for adding an item is invalid. + */ //@@author isaaceng7 public static void printInvalidAddSyntax(String message) { System.out.println(LINE); @@ -90,6 +168,18 @@ public static void printInvalidAddSyntax(String message) { System.out.println(LINE); } + //@@author + + /** + * The function `printTransactionTypeError` prints an error message for an + * invalid transaction type + * in Java. + * + * @param message The `message` parameter is a string that represents the + * specific error message related + * to an invalid transaction type. + */ + //@@author isaaceng7 public static void printTransactionTypeError(String message) { System.out.println(LINE); System.out.println(TAB_SPACE + "Invalid transaction type: " + message); @@ -97,6 +187,18 @@ public static void printTransactionTypeError(String message) { System.out.println(LINE); } + //@@author + + /** + * The function `printNumberFormatError` prints an error message related to + * number format issues in + * Java. + * + * @param message The `message` parameter is a string that represents the error + * message + * related to a number format issue. + */ + //@@author isaaceng7 public static void printNumberFormatError(String message) { System.out.println(LINE); System.out.println(TAB_SPACE + "Error occurred with the input: " + message); @@ -104,6 +206,18 @@ public static void printNumberFormatError(String message) { System.out.println(LINE); } + //@@author + + /** + * The function `printEmptyArgumentError` prints an error message reminding the + * user to include + * proper argument in a command. + * + * @param message The `message` parameter is used to specify the type of + * argument that is + * missing in the command. + */ + //@@author isaaceng7 public static void printEmptyArgumentError(String message) { System.out.println(LINE); System.out.println(TAB_SPACE + "Please include the " + message + "in the command."); @@ -111,6 +225,19 @@ public static void printEmptyArgumentError(String message) { } //@@author + + /** + * The `printAllTransactions` function prints a formatted list of transaction + * details from an + * ArrayList of Transaction objects. + * + * @param transactions The `printAllTransactions` method takes an `ArrayList` of + * `Transaction` + * objects as a parameter. It then iterates over each + * `Transaction` object in the list and prints + * out the details of each transaction in a formatted + * table-like structure. + */ public static void printAllTransactions(ArrayList transactions) { int index = transactions.size(); System.out.println(LINE); @@ -135,7 +262,11 @@ public static void printAllTransactions(ArrayList transactions) { System.out.println(LINE); } - + /** + * The function `printGoodBye` prints a farewell message with a reminder to keep + * track of future + * transactions. + */ public static void printGoodBye() { System.out.println(LINE); System.out.println(TAB_SPACE + @@ -143,6 +274,10 @@ public static void printGoodBye() { System.out.println(LINE); } + /** + * The function `printNoCommandExists` prints a message indicating that no such + * command exists. + */ public static void printNoCommandExists() { System.out.println(LINE); System.out.println(TAB_SPACE + "No such command exists."); @@ -150,6 +285,21 @@ public static void printNoCommandExists() { } //@@author Vavinan + /** + * The function `getEditInformation` prompts the user to edit transaction + * details and returns the + * updated information as a formatted string. + * + * @param string The `getEditInformation` method takes a `String` parameter + * named `string`, which + * represents the transaction information that needs to be edited. + * The method then prompts the user + * to enter new values for the transaction type, description, + * date, amount, and category. + * @return The `getEditInformation` method is returning a formatted string that + * contains the edited + * transaction information. + */ public static String getEditInformation(String string) { System.out.println(LINE); System.out.println(TAB_SPACE + "Please edit the following transaction"); @@ -176,16 +326,32 @@ public static String getEditInformation(String string) { } //@@author + /** + * The function `printUpdatedTransaction` prints a success message along with + * the updated + * transaction details. + * + * @param t The parameter `t` is an object of the `Transaction` class. This + * method is designed to + * print a message indicating that the transaction was updated + * successfully, followed by + * the details of the updated transaction object `t`. + */ public static void printUpdatedTransaction(Transaction t) { System.out.println("\n" + TAB_SPACE + "Updated Successfully"); System.out.println(t.toString()); System.out.println(LINE); } - public static void printAllCommands(){ + /** + * The function `printAllCommands` prints a list of available commands with + * their syntax and + * further help options. + */ + public static void printAllCommands() { System.out.println(HELP_BORDER); System.out.printf("%-20s %-75s %-20s%n", "Command", "Syntax", "Further help"); - System.out.printf("%-20s %-75s %-20s%n","Add","add /t/[TYPE] /n/[DESCRIPTION] /d/[DD-MM-YYYY] " + + System.out.printf("%-20s %-75s %-20s%n", "Add", "add /t/[TYPE] /n/[DESCRIPTION] /d/[DD-MM-YYYY] " + "/$/[AMOUNT] /c/[CATEGORY]", "help add"); System.out.printf("%-20s %-75s %-20s%n", "Edit", "edit [INDEX]", "help edit"); System.out.printf("%-20s %-75s %-20s%n", "Delete", "delete [INDEX]", "help delete"); @@ -194,14 +360,19 @@ public static void printAllCommands(){ } - public static void printAddHelp(){ + /** + * The function `printAddHelp` prints out helpful information and syntax + * examples for adding + * entries with different categories. + */ + public static void printAddHelp() { System.out.println(HELP_BORDER); System.out.println("Method 1:"); System.out.println(TAB_SPACE + "SYNTAX : add /t/[TYPE] /n/[DESCRIPTION] /d/[DD-MM-YYYY]" + "/$/[AMOUNT] \n"); System.out.println("followed by choosing category from the given list:"); - for(Category category : Category.values()) { + for (Category category : Category.values()) { System.out.println(TAB_SPACE + TAB_SPACE + category.getCategoryName() + ": " + category.getCategoryNum()); } @@ -213,15 +384,25 @@ public static void printAddHelp(){ System.out.println(HELP_BORDER); } - public static void printDeleteHelp(){ + /** + * The function `printDeleteHelp` prints out syntax and guidelines for deleting + * an item from a + * transaction list. + */ + public static void printDeleteHelp() { System.out.println(HELP_BORDER); System.out.println(TAB_SPACE + "SYNTAX : delete [INDEX] \n"); - System.out.println( TAB_SPACE + "Make sure the index is above 0 and below or equal to the size of " + + System.out.println(TAB_SPACE + "Make sure the index is above 0 and below or equal to the size of " + "the transaction list"); System.out.println(HELP_BORDER); } - public static void printEditHelp(){ + /** + * The function `printEditHelp` provides guidance on how to use the "edit" + * command in a Java + * program for managing transactions. + */ + public static void printEditHelp() { System.out.println(HELP_BORDER); System.out.println(TAB_SPACE + "SYNTAX : edit [INDEX] \n"); System.out.println("Make sure the index is above 0 and below or equal to the size of the " + @@ -231,14 +412,19 @@ public static void printEditHelp(){ " Enter description: [NEW DESCRIPTION] \n" + " Enter transaction date: [NEW DATE] \n" + " Enter transaction amount: [NEW AMOUNT] \n" + " \n"); - System.out.println("Then you will be given categories to choose from (like as add command). \n"+ + System.out.println("Then you will be given categories to choose from (like as add command). \n" + " In which category do you want to list this transaction? [Enter number between 1 and " + "9]\n" + " Enter Category: [NEW CATEGORY] "); System.out.println(HELP_BORDER); } - public static void printListHelp(){ + /** + * The function `printListHelp` prints out a help message with syntax and + * available options for + * viewing transactions. + */ + public static void printListHelp() { System.out.println(HELP_BORDER); System.out.println(TAB_SPACE + "SYNTAX : list \n"); System.out.println(TAB_SPACE + "This will give some available options to choose from:"); @@ -249,11 +435,16 @@ public static void printListHelp(){ " 4. Custom Date Transactions\n"); System.out.println("From this you can choose 1-4 :"); System.out.println("To print Custom date transaction: \n" + - " 4\n" +"Start Date: [dd-MM-yyyy]\n" + "End Date: [dd-MM-yyyy] "); + " 4\n" + "Start Date: [dd-MM-yyyy]\n" + "End Date: [dd-MM-yyyy] "); System.out.println(HELP_BORDER); } - public static void printUseAvailableHelp(){ + /** + * The function `printUseAvailableHelp` prints out a list of available commands + * for getting help + * related to transactions and accounts. + */ + public static void printUseAvailableHelp() { System.out.println(HELP_BORDER); System.out.println(TAB_SPACE + "Please use the following commands for help"); System.out.println(TAB_SPACE + "To get idea about all commands use: help all"); @@ -266,6 +457,10 @@ public static void printUseAvailableHelp(){ } //@@author isaaceng7 + /** + * The function `printListOptions` displays a menu of transaction viewing + * options. + */ public static void printListOptions() { System.out.println(LINE); System.out.println("What would you like to view?"); @@ -277,12 +472,33 @@ public static void printListOptions() { System.out.println(TAB_SPACE + "6. Category Transactions"); System.out.println(LINE); } + //@@author + + /** + * The function `getListOption` reads a user input as a String and returns it. + * + * @return This method returns a String value that is read from the user input + * using the `Scanner` object `in`. + */ + //@@author isaaceng7 public static String getListOption() { String data = in.next(); in.nextLine(); return data; } + //@@author + + /** + * The function `getStartDate()` prompts the user for a start date input and + * returns the entered + * data as a String. + * + * @return The method `getStartDate()` returns a String value, which is the user + * input for the + * start date. + */ + //@@author isaaceng7 public static String getStartDate() { System.out.print("Start Date: "); String data = in.next(); @@ -290,6 +506,18 @@ public static String getStartDate() { return data; } + //@@author + + /** + * The function `getEndDate()` prompts the user for an end date input and + * returns the entered data + * as a String. + * + * @return The method `getEndDate()` is returning a String value that represents + * the end date + * entered by the user. + */ + //@@author isaaceng7 public static String getEndDate() { System.out.print("End Date: "); String data = in.next(); @@ -297,6 +525,17 @@ public static String getEndDate() { return data; } + //@@author + + /** + * The function `printAccountList` prints a list of account numbers and names in + * a formatted table. + * + * @param accounts An ArrayList of Account objects. Each Account object + * represents an account with + * an account number and a name. + */ + //@@author isaaceng7 public static void printAccountList(ArrayList accounts) { int maxIndex = accounts.size(); System.out.println(LINE); @@ -316,7 +555,19 @@ public static void printAccountList(ArrayList accounts) { System.out.println("\n" + TAB_SPACE + ACCOUNT_TABLE_BORDER); System.out.println(LINE); } + //@@author + /** + * The function `getSelectedAccountNumber` prompts the user to select an account + * number from a list + * of accounts and returns the selected account number as a String. + * + * @param accounts An ArrayList of Account objects. + * @return The method `getSelectedAccountNumber` returns a `String` value, which + * is the account + * number selected by the user from the list of accounts provided. + */ + //@@author isaaceng7 public static String getSelectedAccountNumber(ArrayList accounts) { printAccountList(accounts); System.out.print("Account number: "); @@ -325,17 +576,42 @@ public static String getSelectedAccountNumber(ArrayList accounts) { return data; } + //@@author + + /** + * The function `getSelectedCategory` prompts the user to select a category + * number and returns the + * integer value entered by the user. + * + * @return The method `getSelectedCategory` is returning an integer value + * representing the selected + * category number entered by the user. + */ + //@@author isaaceng7 public static int getSelectedCategory() { System.out.print("Select a category number: "); String data = in.nextLine(); return Integer.parseInt(data); } + //@@author + /** + * The function `printPastTransactions` prints a formatted list of past + * transactions based on a + * specified duration. + * + * @param transactions transactions is an ArrayList that contains Transaction + * objects. + * @param duration The `duration` parameter is a String that represents the + * time period for + * which the user want to display past transactions. + */ + //@@author isaaceng7 public static void printPastTransactions(ArrayList transactions, String duration) { int index = transactions.size(); System.out.println(LINE); - System.out.println(TAB_SPACE + "Displaying transactions from the past " + duration + ":"); + System.out.println(TAB_SPACE + "Displaying transactions from the past " + duration + ":"); System.out.println(TAB_SPACE + TABLE_BORDER); System.out.printf(TAB_SPACE + TAB_SPACE + "%-5s %-10s %-20s %-20s %-30s %-15s %-15s %-15s%n", "ID", "Type", "Account Number", "Account Name", "Transaction", "Date", "Amount", "Category"); @@ -357,6 +633,21 @@ public static void printPastTransactions(ArrayList transactions, St } + //@@author + + /** + * The `printCustomDateTransactions` function prints a formatted list of + * transactions within a + * specified date range. + * + * @param transactions The `printCustomDateTransactions` method takes an + * `ArrayList` of + * `Transaction` objects as input. It then iterates over the + * transactions in the list and prints + * out specific details of each transaction in a formatted + * table-like structure. + */ + //@@author isaaceng7 public static void printCustomDateTransactions(ArrayList transactions) { int index = transactions.size(); System.out.println(LINE); @@ -381,14 +672,35 @@ public static void printCustomDateTransactions(ArrayList transactio System.out.println(LINE); } + //@@author + + /** + * The function `printAccountTransactions` prints a formatted list of + * transactions for a specific + * account. + * + * @param transactions An ArrayList of Transaction objects containing the + * transaction details. + * @param accountName The `accountName` parameter in the + * `printAccountTransactions` method is a + * `String` that represents the name of the account for + * which the user want to display transactions. + * @param accountNumber The `accountNumber` parameter in the + * `printAccountTransactions` method is + * an integer value that represents the account number of + * the account for which the user want to display + * transactions. + */ + //@@author isaaceng7 public static void printAccountTransactions(ArrayList transactions, String accountName, int accountNumber) { int index = transactions.size(); System.out.println(LINE); - System.out.println(TAB_SPACE + "Displaying transactions of account: " + accountName + "(" + accountNumber +")"); + System.out + .println(TAB_SPACE + "Displaying transactions of account: " + accountName + "(" + accountNumber + ")"); System.out.println(TAB_SPACE + TABLE_BORDER); System.out.printf(TAB_SPACE + TAB_SPACE + "%-5s %-10s %-30s %-15s %-15s %-15s%n", "ID", "Type", - "Transaction", "Date", "Amount", "Category"); + "Transaction", "Date", "Amount", "Category"); for (int i = START_INDEX; i < index; i++) { Transaction transaction = transactions.get(i); String type = transaction.getTransactionType(); @@ -404,6 +716,20 @@ public static void printAccountTransactions(ArrayList transactions, System.out.println(LINE); } + //@@author + + /** + * The function `printCategoryTransactions` prints out a formatted list of + * transactions belonging + * to a specific category. + * + * @param transactions transactions is an ArrayList that contains Transaction + * objects. + * @param categoryName Category name is a string representing the name of a + * category for which the + * user want to display transactions. + */ + //@@author isaaceng7 public static void printCategoryTransactions(ArrayList transactions, String categoryName) { int index = transactions.size(); System.out.println(LINE); @@ -427,9 +753,17 @@ public static void printCategoryTransactions(ArrayList transactions System.out.println(LINE); } - //@@author + /** + * The function `printAddAccountMessage` takes a string representing an account, + * splits it into + * parts, and prints each part with proper formatting. + * + * @param account The parameter `account` is expected to contain account + * information separated + * by the pipe character `|`. + */ //@@author vibes-863 public static void printAddAccountMessage(String account) { String[] parts = account.split("\\|"); @@ -441,6 +775,18 @@ public static void printAddAccountMessage(String account) { System.out.println(LINE); } + //@@author + + /** + * The function `printInvalidArgumentSyntax` prints an error message along with + * a reminder to + * ensure correct argument entry. + * + * @param message The `message` parameter is a string that contains the specific + * error message to + * be displayed when the argument syntax is invalid. + */ + //@@author vibes-863 public static void printInvalidArgumentSyntax(String message) { System.out.println(LINE); System.out.println(TAB_SPACE + message); @@ -448,6 +794,16 @@ public static void printInvalidArgumentSyntax(String message) { System.out.println(LINE); } + //@@author + + /** + * The function `printListOfAccounts` prints a formatted list of account details + * including account + * number, name, and balance. + * + * @param accounts An ArrayList of Account objects. + */ + //@@author vibes-863 public static void printListOfAccounts(ArrayList accounts) { int maxIndex = accounts.size(); System.out.println(LINE); @@ -462,12 +818,28 @@ public static void printListOfAccounts(ArrayList accounts) { String name = account.getName(); double balance = account.getBalance(); - System.out.printf("\n" +TAB_SPACE + TAB_SPACE + "%-20d %-30.45s %-15.2f", accountNumber, name, balance); + System.out.printf("\n" + TAB_SPACE + TAB_SPACE + "%-20d %-30.45s %-15.2f", accountNumber, name, balance); } System.out.println("\n" + TAB_SPACE + ACCOUNT_TABLE_BORDER); System.out.println(LINE); } + //@@author + + /** + * The function `printDeleteAccountMessage` prints a message confirming the + * deletion of an account + * and lists the transactions related to that account that have also been + * removed. + * + * @param account The `account` parameter is a string that contains + * account information. + * @param transactionsRemoved The `transactionsRemoved` parameter is an + * ArrayList of + * Transaction objects that represent the + * transactions related to the account + */ + //@@author vibes-863 public static void printDeleteAccountMessage(String account, ArrayList transactionsRemoved) { String[] parts = account.split("\\|"); System.out.println(LINE); @@ -486,7 +858,7 @@ public static void printDeleteAccountMessage(String account, ArrayList transactions, ArrayList indices) { - if(transactions.isEmpty()) { + if (transactions.isEmpty()) { System.out.println("No matching Transactions found"); - } else{ + } else { System.out.println("Search results:"); System.out.println(TAB_SPACE + TABLE_BORDER); System.out.printf(TAB_SPACE + TAB_SPACE + "%-5s %-10s %-20s %-20s %-30s %-15s %-15s %-15s%n", "ID", "Type", "Account Number", "Account Name", "Transaction", "Date", "Amount", "Category"); int i = 0; for (Transaction t : transactions) { - //System.out.println((indices.get(i) + 1) + ". " + transactions.get(i)); + // System.out.println((indices.get(i) + 1) + ". " + transactions.get(i)); System.out.printf(TAB_SPACE + TAB_SPACE + "%-5d %-10s %-20d %-20.45s %-30.45s %-15s %-15.2f %-15s%n", - indices.get(i)+1, t.getTransactionType(),t.getAccountNumber(),t.getAccountName(), + indices.get(i) + 1, t.getTransactionType(), t.getAccountNumber(), t.getAccountName(), t.getDescription(), t.getDate(), t.getAmount(), t.getCategory().getCategoryName()); i++; } @@ -565,24 +1006,56 @@ public static void printSearchResults(ArrayList transactions, Array } + /** + * The function `printInvalidCategoryError` prints an error message for an + * invalid category. + */ + //@@author ShyamKrishna33 public static void printInvalidCategoryError() { System.out.println(LINE); System.out.println(TAB_SPACE + "Invalid Category"); System.out.println(LINE); } + //@@author + + /** + * The function `printInvalidAccountNameError` prints an error message stating + * that the Account + * Name cannot be blank. + */ + //@@author ShyamKrishna33 private static void printInvalidAccountNameError() { System.out.println(LINE); System.out.println(TAB_SPACE + "Account Name cannot be blank"); System.out.println(LINE); } + //@@author + + /** + * The function `printInvalidAccountBalanceError` prints an error message the + * invalid account balance. + */ + //@@author ShyamKrishna33 private static void printInvalidAccountBalanceError() { System.out.println(LINE); System.out.println(TAB_SPACE + "Account Balance cannot be a valid number"); System.out.println(LINE); } + //@@author + + /** + * The function `getInitialAccountName` prompts the user to input a name for + * their account and + * validates it to ensure it is not empty. + * + * @return The method `getInitialAccountName()` returns a `String` value, which + * is the account name + * entered by the user. + */ + //@@author ShyamKrishna33 public static String getInitialAccountName() { System.out.println("Let's first create an account for you! What do you want to call it?"); String accountName = in.nextLine(); @@ -594,6 +1067,18 @@ public static String getInitialAccountName() { return accountName; } + //@@author + + /** + * The function `getInitialAccountBalance` prompts the user to input an initial + * account balance and + * handles any input errors. + * + * @return The method `getInitialAccountBalance()` returns a `Double` value, + * which represents the + * initial account balance entered by the user. + */ + //@@author ShyamKrishna33 public static Double getInitialAccountBalance() { System.out.println("Great! What's the initial balance?"); double initialBalance = 0;