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 long
The unique account number for the user.private double
The current balance of the account.private long
The mobile number linked to the account.private String
The password used for authentication.private final String
The 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 void
deposit
(double amount) Deposits the specified amount into the account balance.protected long
Retrieves the account number of the user.protected double
Retrieves the current balance of the account.protected long
Retrieves the mobile number linked to the account.protected String
Retrieves the username associated with the account.protected boolean
isMobileNumberRegistered
(long mobileNumber) Checks if the given mobile number is already registered.protected boolean
isUserValid
(long accountNumber, String password) Validates the user by checking the account number and password.protected void
setMobileNumber
(long mobileNumber) Updates the mobile number associated with the account.protected void
setPassword
(String password) Updates the password of the account.protected void
withdraw
(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:
true
if 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:
true
if 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.
-