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

Assume the existence of an interface, Account, with the following methods : - de

ID: 3779303 • Letter: A

Question

Assume the existence of an interface, Account, with the following methods : - deposit: accepts an integer parameter and returns an integer - withdraw: accepts an integer parameter and return a boolean Define a class , BankAccount, that implements the above interface and has the following members: - an instance variable named balance - a constructor that accepts an integer that is used to initialize the instance variable - an implementation of the deposit method that adds its parameter to the balance variable . The new balance is returned as the value of the method . - an implementation of the withdraw method that checks whether its parameter is less than or equal to the balance and if so, decreases the balance by the value of the parameter and returns true ; otherwise, it leaves the balance unchanged and returns false .

Explanation / Answer

Account Interface:

public interface Account {

   public int deposit(int depostCash);
   public boolean withdraw(int withdrawCash);
      
}

BankAccount Class:

public class BankAccount implements Account{

   private int balance;
  
   public BankAccount(int initialBalance) {
       this.balance = initialBalance;
   }
   @Override
   public int deposit(int depostCash) {
       balance = balance + depostCash;
       return balance;
   }

   @Override
   public boolean withdraw(int withdrawCash) {
       if(balance>=withdrawCash){
           balance = balance - withdrawCash;
           return true;
       }
       return false;
   }

}

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