Package username
Class BankAccount
java.lang.Object
username.BankAccount
Class that represents a Bank Account.
-
Constructor Summary
ConstructorDescriptionBankAccount
(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 TypeMethodDescriptionint
deposit
(double amount) Increases the balance by the specified amount if the amount is greater than or equal to zero.int
getAge()
Gets the age of the account holder.double
Gets the balance of the account.getName()
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
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.
-
Constructor Details
-
BankAccount
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
Sets the name of the account holder with the passed-in value.- Parameters:
name
- Value to set to name.
-
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
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.
-