Package Databases
Class AccountDatabase
java.lang.Object
Common.Database
Databases.AccountDatabase
The
AccountDatabase
class manages a collection of Account
objects, providing functionalities to create, search, print, and remove
accounts from the database.-
Field Summary
Fields inherited from class Common.Database
csvPath, headerFormat, records
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs anAccountDatabase
with a default CSV path for account credentials.AccountDatabase
(String csvpath) Constructs anAccountDatabase
with a specified CSV path for account credentials. -
Method Summary
Modifier and TypeMethodDescriptioncreateDatabaseItem
(String[] values) Creates a newAccount
object from the provided values.void
Prints all items in the account database with a specified header.boolean
removeItem
(String userid) Removes an account from the database using the specified user ID.searchItem
(String id) Searches for an account in the database using the specified user ID.Methods inherited from class Common.Database
addItem, extractFromCSV, getRecords, printItems, setcsvPath, setHeaderFormat, storeToCSV
-
Constructor Details
-
AccountDatabase
public AccountDatabase()Constructs anAccountDatabase
with a default CSV path for account credentials. Initializes the header format and extracts data from the specified CSV file. -
AccountDatabase
Constructs anAccountDatabase
with a specified CSV path for account credentials.- Parameters:
csvpath
- the path to the CSV file containing account credentials
-
-
Method Details
-
createDatabaseItem
Creates a newAccount
object from the provided values.- Specified by:
createDatabaseItem
in classDatabase
- 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 classDatabase
-
searchItem
Searches for an account in the database using the specified user ID.- Specified by:
searchItem
in classDatabase
- Parameters:
id
- the unique identifier of the account to search for- Returns:
- the
Account
object if found; otherwise, returns null
-
removeItem
Removes an account from the database using the specified user ID.- Specified by:
removeItem
in classDatabase
- Parameters:
userid
- the unique identifier of the account to be removed- Returns:
- true if the account was successfully removed; false otherwise
-