Answer:
see explaination
Explanation:
Please find my detailed implementation.
I have tested with Single Bank account object.
You can create array list of Bank Account in test program:
public class BankAccount {
private String name;
private int accountNumber;
private int PIN;
private double balance;
public BankAccount(int accN, int pin) {
accountNumber = accN;
PIN = pin;
}
public BankAccount () {
name = "Undefined";
accountNumber = 0;
PIN = 0;
balance = 0;
}
public String getName() {
return name;
}
public int getAccountNumber() {
return accountNumber;
}
public int getPIN() {
return PIN;
}
public double getBalance() {
return balance;
}
public void setName(String name) {
this.name = name;
}
public void setAccountNumber(int accountNumber) {
this.accountNumber = accountNumber;
}
public void setPIN(int pIN) {
PIN = pIN;
}
public void setBalance(double balance) {
this.balance = balance;
}
public void withdrawal(double amount) {
if(amount <= balance) {
balance = balance - amount;
}
}
public void deposit(double amount) {
balance += amount;
}
public void transferFunds (double amount, BankAccount toBankAccount) {
if(amount >= balance) {
toBankAccount.setBalance(amount + toBankAccount.getBalance());
balance -= amount;
}
}
atOverride //change the at with the at symbol
public String toString() {
return "{id:"+accountNumber+", name:"+name+", pin:"+PIN+", balance:$"+balance+"}";
}
}
#########
public class BankAccountTest {
public static void main(String[] args) {
BankAccount myAccount = new BankAccount(526323450, 1234);
myAccount.setName("Pravesh");
myAccount.setBalance(345.64);
System.out.println(myAccount);
BankAccount anotherAccount = new BankAccount(); //default constructor
System.out.println(anotherAccount);
}
}