Class UserAccount

java.lang.Object
com.myBank.bankServer.UserAccount

public class UserAccount extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    private 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

    Constructors
    Constructor
    Description
    UserAccount(String userName, long accountNumber, String password, long mobileNumber)
    Constructs a new user account with the specified details.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected 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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • USERNAME

      private final String USERNAME
      The username associated with the account.
    • ACCOUNTNUMBER

      private final long ACCOUNTNUMBER
      The unique account number for the user.
    • password

      private String password
      The password used for authentication.
    • mobileNumber

      private long mobileNumber
      The mobile number linked to the account.
    • balance

      private double balance
      The current balance of the account.
  • Constructor Details

    • UserAccount

      UserAccount(String userName, long accountNumber, String password, long mobileNumber)
      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

      protected String 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

      protected void setPassword(String password)
      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

      protected boolean isUserValid(long accountNumber, String password)
      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, otherwise false.
    • 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, otherwise false.
    • 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.