Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1 Write a lava cdlass called BankAccount Parts of the codle is evn beéloel ing)

ID: 3906255 • Letter: 1

Question

1 Write a lava cdlass called BankAccount Parts of the codle is evn beéloel ing) and balance (double) and three methos depost (doubie mout withdrawddouble amount) and dsplayBalance account causing the current balance to increae, withdorau nethod wihdrawn the anout causing the current balance to decrease and dsplayalence method prests out the name and the current balance separated by a comma For eale e ake and bca 400 it should print deposit method deposits he amoust to he ake,$40.00 public class Banascount //Define Instance variables beze tring nane: //Define Instance nethods bere public void deposit (double anount) balance balance anount: Baniklcount object called 8 and asg Write a dlient program called BankAccountchient that creates a ohn" to its name field and 1000 to balance field. Call the deposit method to deposit 500 to thsacout and call the display method to display the current balance Then, withdra 00fro ts account and call the display method to display the current balance Create another object caled 82 nd diglay the name and current balance for this object

Explanation / Answer

BankAccountClient.java

public class BankAccountClient {

public static void main(String[] args) {

BankAccount B1 = new BankAccount();

B1.deposit(500);

B1.displayBalance();

B1.withdraw(300);

B1.displayBalance();

BankAccount B2 = new BankAccount();

B2.displayBalance();

}

}

BankAccount.java

public class BankAccount {

private String name;

private double balance;

public BankAccount() {

this.balance = 1000;

this.name = "John";

}

public void deposit(double amount) {

balance+=amount;

}

public void withdraw(double amount) {

balance-=amount;

}

public void displayBalance() {

System.out.println(name+", $"+balance);

}

}

Output:

John, $1500.0
John, $1200.0
John, $1000.0