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

Classes: BankAccount: -balance , customer Customer(conncted to bankaccount): -na

ID: 3723806 • Letter: C

Question

Classes:

BankAccount:

-balance , customer

Customer(conncted to bankaccount):

-name , id

ChequingAccount:

-overdraftFee, overdraftAmount

Additional information:

1)The instance variable overdraftAmount should be moved from BankAccount to ChequingAccount. The withdraw method in BankAccount should ensure the balance is never below zero.

2)The method transfer in BankAccount should transfer specified amount from the account the method is invoked on to the account provided as an argument. The method should do this by invoking the withdraw and deposit methods.

3)The method setBalance in BankAccount should have protected access so child classes can access it. It should do not do any error checking (and it should allow a negative balance.)

4)ChequingAccount overrides the withdraw method such that it allows an overdraft of at most overdraftAmount. (The balance is allowed to be negative.) If the withdraw results in an overdraft (the balance in the account is negative), the customer should be charged the overdraftFee. (The charge is done by reducing the account balance by the overdraftFee amount.)

I need help tracing this java code on paper! Thank you

Customer c = new Customer ("John Doe", 321); BankAccount b1 = new BankAccount (c, 100.0); cheguingAccount b2 = new CheguingAccount (c, 200.0, 12.0); b2.setOverdraftAmount (150.0); BankAccount b3 = b2; System.out.println (bl.getBalance ()+", " + b3.getBalance O) b1.withdraw (110); System.out.printin (b1.getBalance )+","+ b3.getBalance )) b2.withdraw (300.0) System.out.println (b1.getBalance )+","+ b3.getBalance ()); bl.transfer (50.0, b2) System.out.println (bl.getBalance )+","+ b3.getBalance ()) b2.transfer (88, bl) System.out.println (bl.getBalance ()+", " + b3.getBalance ))

Explanation / Answer

here is your classes : -------->>>>>>>>

BankAccount.java : ---------->>>

public class BankAccount{
private double balance;
private Customer customer;

public BankAccount(Customer cust,double bal){
  balance = bal;
  customer = cust;
}

protected void setBalance(double bal){
  balance bal;
}

public void getBalance(){
  return balance;
}

public int withdraw(double bal){
  if(bal > balance){
   return 0;
  }

  balance = balance - bal;
  return 1;
}
public void deposit(double bal){
  balance = balance + bal;
}

public void transfer(double bal,BankAccount b){
  int n = withdraw(bal);
  if(n == 1)
   b.deposit(bal);
}
}

Customer.java : ---------->>>>..

public class Customer{
private String name;
private int id;

public Customer(String n,int id){
  name = n;
  this.id = id;
}

public void getName(){
  return name;
}

public void getID(){
  return id;
}
}

CheckingAccount.java : ---------->>>>>..


public class CheckingAccount extends BankAccount{
private double overdraftAmount;
private double overdraftFee;

public CheckingAccount(Customer c,double bal,double overFee){
  super(c,bal);
  overdraftFee = overFee;
}

public void setOverdraftAmount(double bal){
  if(bal < 0){
   return;
  }

  overdraftAmount = bal;
}

public int withdraw(double bal){
  double b = getBalance();
  if(bal > b+overdraftAmount){
   return 0;
  }
  setBalance(b - bal);
  b = getBalance();
  if(b < 0){
   setBalance(b - overdraftFee);
  }
  return 1;
}

public void trasfer(double bal,BankAccount b){
  int n = this.withdraw(bal);
  if(n == 1)
  b.deposit(bal);
}
}