Package com.myBank.bankServer
Class UserAccount
java.lang.Object
com.myBank.bankServer.UserAccount
Represents a user account in the bank system.
Stores account details including username, account number, password,
mobile number, and balance. Provides methods for updating and
retrieving account information.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final longThe unique account number for the user.private doubleThe current balance of the account.private longThe mobile number linked to the account.private StringThe password used for authentication.private final StringThe username associated with the account. -
Constructor Summary
ConstructorsConstructorDescriptionUserAccount(String userName, long accountNumber, String password, long mobileNumber) Constructs a new user account with the specified details. -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddeposit(double amount) Deposits the specified amount into the account balance.protected longRetrieves the account number of the user.protected doubleRetrieves the current balance of the account.protected longRetrieves the mobile number linked to the account.protected StringRetrieves the username associated with the account.protected booleanisMobileNumberRegistered(long mobileNumber) Checks if the given mobile number is already registered.protected booleanisUserValid(long accountNumber, String password) Validates the user by checking the account number and password.protected voidsetMobileNumber(long mobileNumber) Updates the mobile number associated with the account.protected voidsetPassword(String password) Updates the password of the account.protected voidwithdraw(double amount) Withdraws the specified amount from the account balance.
-
Field Details
-
USERNAME
The username associated with the account. -
ACCOUNTNUMBER
private final long ACCOUNTNUMBERThe unique account number for the user. -
password
The password used for authentication. -
mobileNumber
private long mobileNumberThe mobile number linked to the account. -
balance
private double balanceThe current balance of the account.
-
-
Constructor Details
-
UserAccount
Constructs a new user account with the specified details.- Parameters:
userName- The username for the account.accountNumber- The unique account number.password- The password for authentication.mobileNumber- The mobile number linked to the account.
-
-
Method Details
-
getUSERNAME
Retrieves the username associated with the account.- Returns:
- The username of the account.
-
getAccountNumber
protected long getAccountNumber()Retrieves the account number of the user.- Returns:
- The account number.
-
getBalance
protected double getBalance()Retrieves the current balance of the account.- Returns:
- The current balance.
-
getMobileNumber
protected long getMobileNumber()Retrieves the mobile number linked to the account.- Returns:
- The mobile number.
-
setPassword
Updates the password of the account.- Parameters:
password- The new password to set.
-
setMobileNumber
protected void setMobileNumber(long mobileNumber) Updates the mobile number associated with the account.- Parameters:
mobileNumber- The new mobile number to set.
-
isUserValid
Validates the user by checking the account number and password.- Parameters:
accountNumber- The account number to verify.password- The password to verify.- Returns:
trueif the credentials match, otherwisefalse.
-
isMobileNumberRegistered
protected boolean isMobileNumberRegistered(long mobileNumber) Checks if the given mobile number is already registered.- Parameters:
mobileNumber- The mobile number to check.- Returns:
trueif the mobile number is registered, otherwisefalse.
-
withdraw
protected void withdraw(double amount) Withdraws the specified amount from the account balance. Displays an error message if funds are insufficient.- Parameters:
amount- The amount to withdraw.
-
deposit
protected void deposit(double amount) Deposits the specified amount into the account balance. Displays an error message if the amount is invalid.- Parameters:
amount- The amount to deposit.
-