Package username

Class BankAccount

java.lang.Object
username.BankAccount

public class BankAccount extends Object
Class that represents a Bank Account.
  • Constructor Summary

    Constructors
    Constructor
    Description
    BankAccount(String name, int age, String pin)
    Creates a new instance of a Bank Account with the name, age, and pin of the account holder.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    deposit(double amount)
    Increases the balance by the specified amount if the amount is greater than or equal to zero.
    int
    Gets the age of the account holder.
    double
    Gets the balance of the account.
    Gets the name of the account holder.
    void
    setAge(int age)
    Sets the age of the account holder with the passed-in value.
    void
    Sets the name of the account holder with the passed-in value.
    int
    withdraw(String pin, double amount)
    Reduces the account balance by the specified amount if the pin matches the current pin and the amount is positive and less than or equal to the current account balance.

    Methods inherited from class java.lang.Object

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

    • BankAccount

      public BankAccount(String name, int age, String pin)
      Creates a new instance of a Bank Account with the name, age, and pin of the account holder.
      Parameters:
      name - Name of the account holder.
      age - Age of the account holder.
      pin - Pin of the account holder.
  • Method Details

    • setName

      public void setName(String name)
      Sets the name of the account holder with the passed-in value.
      Parameters:
      name - Value to set to name.
    • getName

      public String getName()
      Gets the name of the account holder.
      Returns:
      Name of the account holder.
    • setAge

      public void setAge(int age)
      Sets the age of the account holder with the passed-in value.
      Parameters:
      age - Value to set to age.
    • getAge

      public int getAge()
      Gets the age of the account holder.
      Returns:
      Age of the account holder.
    • getBalance

      public double getBalance()
      Gets the balance of the account.
      Returns:
      Balance of the account.
    • withdraw

      public int withdraw(String pin, double amount)
      Reduces the account balance by the specified amount if the pin matches the current pin and the amount is positive and less than or equal to the current account balance. Returns 1 if the balance is successfully reduced, else returns -1.
      Parameters:
      pin - Pin value to test.
      amount - Amount to reduce the current balance.
      Returns:
      1 if the amount was withdrawn, else -1.
    • deposit

      public int deposit(double amount)
      Increases the balance by the specified amount if the amount is greater than or equal to zero. Returns 1 if the balance is successfully increased, else returns -1.
      Parameters:
      amount - Amount to add to the current balance.
      Returns:
      1 if the balance was changed, else -1.