Question
Given the BankAccount class as below /** * A bank account has a balance that can be changed by deposits and * withdrawals. */ public
Given the BankAccount class as below
/**
* A bank account has a balance that can be changed by deposits and
* withdrawals.
*/
public class BankAccount {
private double balance;
private String owner;
/**
* Constructs a bank account with a zero balance.
*/
public BankAccount() {
balance = 0;
owner=null;
}
/**
* Constructs a bank account with a given name.
*/
public BankAccount(String name) {
balance = 0;
owner=name;
}
* Constructs a bank account with a givenname and balance.
*/
public BankAccount(String name, double bl) {
balance = bl;
owner=name;
}
/**
* Deposits money into the bank account.
*/
public void deposit(double amount) {
if (amount > 0)
balance = balance + amount;
else System.out.println(owner + ": " + "Wrong operation!");
}
/**
* Withdraws money from the bank account.
*/
public void withdraw(double amount) {
if (balance >= amount)
balance = balance - amount;
else System.out.println(owner + ": " + "No enough balance!");
}
/**
* Gets the current balance of the bank account.
* @return the current balance
*/
public double getBalance() {
return balance;
}
public String getOwner() {
return owner;
}
}
Assume we have a client class that will use the BankAccount class. The main() method of this client class is defined as below.
public static void main(String args[]) {
//1- give a code to declare and initialise array list called "accounts" to storeBankAccountobjects.
//2- give a code to make a new BankAccount object with name "Tom" and balance 100; and add this object to the arrayList "accounts".
//3- give a code to make a new BankAccount object with name "Ben" and balance 200; and add this object at position zero in the arrayList "accounts".
//4- give a code to deposit $100in in "Tom" account.
//5- give a code to withdraw $100from in "Ben" account.
//6- give a for loop codeto printall bank account details, name and balance.
//7-give a code to remove "Tom" bank account
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started