Problem: Download the file BankAccount.java and add it to your lab project. • In main(), create 3 BankAccount objects for “Johnson”, “Arafat” and “Johansson”. The original balances for these customers are $11000, $20000 and $5000 respectively. • Next, the program will deposit 5% in each account • Then the program will transfer $500 from “Johnson” to the other two customers. • Next assume that you do not know the data encapsulated in the 3 objects so display the names and balances of all customers who have their name starting with ‘J’. • Finally, the program will withdraw $100000 from one of three objects. Note: This program has no Input from the keyboard (no user input unless you want to do so). Sample output: Johnson has $10550.0 Johansson has $5750.0 You cannot withdraw that amount!
The form that I had to download was :
class BankAccount {
private double balance;
private String name;
public BankAccount(String n, double initialBalance) {
balance= initialBalance;
name=n;
}
public void deposit(double amount) {
balance += amount;
}
public void withdraw(double amount) {
if (amount<=balance)
balance -= amount;
else
System.out.println("You cannot withdraw that amount !");
}
public double getBalance() {
return balance;
}
public String getName() {
return name;
}
public void transfer (double amount, BankAccount other) {
balance -= amount;
other.balance += amount;
}
}
public class BankAccount1 {
private double balance;
private String name;
public BankAccount1(String n, double initialBalance) {
balance= initialBalance;
name=n;
}
public void deposit(double amount) {
balance += amount;
}
public void withdraw(double amount) {
if (amount<=balance)
balance -= amount;
else
System.out.println("You cannot withdraw that amount !");
}
public double getBalance() {
return balance;
}
public String getName() {
return name;
}
public void transfer (double amount, BankAccount1 other) {
balance -= amount;
other.balance += amount;
}
public static void main(String[] args){
BankAccount1 obj1 = new BankAccount1("Johnson",11000);
BankAccount1 obj2 = new BankAccount1("Arafat",20000);
BankAccount1 obj3 = new BankAccount1("Johansson",5000);
obj1.deposit(550);
obj2.deposit(1000);
obj3.deposit(250);
obj1.transfer(500,obj2);
obj1.transfer(500,obj3);
if(obj1.name.startsWith("J")){
obj1.getBalance();
System.out.println(""+obj1.getName()+" has
"+obj1.getBalance());
}
if(obj2.name.startsWith("J")){
obj2.getBalance();
System.out.println(""+obj2.getName()+" has
"+obj2.getBalance());
}
if(obj3.name.startsWith("J")){
obj3.getBalance();
System.out.println(""+obj3.getName()+" has "
+obj3.getBalance());
}
obj1.withdraw(100000);
}
}
Problem: Download the file BankAccount.java and add it to your lab project. • In main(), create...