Package Databases

Class AccountDatabase

java.lang.Object
Common.Database
Databases.AccountDatabase

public class AccountDatabase extends Database
The AccountDatabase class manages a collection of Account objects, providing functionalities to create, search, print, and remove accounts from the database.
  • Constructor Details

    • AccountDatabase

      public AccountDatabase()
      Constructs an AccountDatabase with a default CSV path for account credentials. Initializes the header format and extracts data from the specified CSV file.
    • AccountDatabase

      public AccountDatabase(String csvpath)
      Constructs an AccountDatabase with a specified CSV path for account credentials.
      Parameters:
      csvpath - the path to the CSV file containing account credentials
  • Method Details

    • createDatabaseItem

      public DatabaseItems createDatabaseItem(String[] values)
      Creates a new Account object from the provided values.
      Specified by:
      createDatabaseItem in class Database
      Parameters:
      values - an array of strings containing account details in the order: name, id, password, role, gender, age
      Returns:
      a new Account object populated with the provided values
    • printItems

      public void printItems()
      Prints all items in the account database with a specified header.
      Specified by:
      printItems in class Database
    • searchItem

      public DatabaseItems searchItem(String id)
      Searches for an account in the database using the specified user ID.
      Specified by:
      searchItem in class Database
      Parameters:
      id - the unique identifier of the account to search for
      Returns:
      the Account object if found; otherwise, returns null
    • removeItem

      public boolean removeItem(String userid)
      Removes an account from the database using the specified user ID.
      Specified by:
      removeItem in class Database
      Parameters:
      userid - the unique identifier of the account to be removed
      Returns:
      true if the account was successfully removed; false otherwise