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;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.