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

Suppose you have a class named BankAccount that represents a bank account. The B

ID: 3540433 • Letter: S

Question

Suppose you have a class named BankAccount that represents a bank account. The BankAccount class has two instance variables:

private double balance

private double annualInterestRate

The BankAccount class also has the following methods.

1. public BankAccount ( double b, double ir )

A constructor that sets the instance variables to the passed-in values.

2. public double checkBalance()

Returns the current balance of this BankAccount object.

3. public double deposit(double amt)

Updates the balance by depositing amt into the account. Returns the new balance.

4. public double withdraw ( double amt )

Updates the balance by withdrawing amt from the account. Returns the new balance.

5. public double payInterest()

Updates the balance by making a single annual interest payment based on the current balance. Returns the new balance.


I. Declare and instantiate a BankAccount object named acct1, with an initial balance of $0 and an annual interest rate of 0.5%.

II. Declare and instantiate a BankAccount object named acct2, with an initial balance of $500 and an annual interest rate of 1.1%.

III. Display the current balances of both acct1 and acct2 on the screen.

IV. Deposit $120 to acct1 and display the new balance on the screen.

V.  Withdraw $80 from acct2 and display the new balance on the screen.

VI. Make an annual interest payment to both acct1 and acct2, and display the new balances of each on the screen.

Explanation / Answer

BankAccount acct1 = new BankAccount(0,0.5);


BankAccount acct2 = new BankAccount(500,1.1);


System.out.Println(acct1.getBalance());

System.out.Println(acct2.getBalance());


acct1.deposit(120);

System.out.Println(acct1.getBalance());


acct2.withdraw(120);

System.out.Println(acct2.getBalance());



System.out.Println(acct1.payInterest());

System.out.Println(acct2.payInterest());

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote