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

Suppose the following BankAccount class has been created: public class BankAccou

ID: 3571446 • Letter: S

Question

Suppose the following BankAccount class has been created:

public class BankAccount {

            String name;

            double balance;

            public void deposit(double amount) {

                        balance = balance + amount;

            }

            public void withdraw(double amount) {

                        balance = balance – amount;

            }

}

Add a field to the BankAccount class named transactionFee for a real number representing an amount of money to deduct every time the user withdraws money. The default value is $0.00, but the client can change the value. Deduct the transaction fee money during every withdraw call (but not from deposits). Make sure that the balance cannot go negative during a withdrawal. If the withdrawal (amount plus transaction fee) would cause it to become negative, don’t modify the balance at all.

Explanation / Answer

BankAccount.java


public class BankAccount {
String name;
double balance;
double transactionFee= 0.00;
public void deposit(double amount) {
balance = balance + amount;
}
public void withdraw(double amount) {
           if(balance - amount - transactionFee >= 0){
balance = balance - amount;
           }
}
}

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