Question: 11. write a completed program based on public boolean transactionFee(double fee) { double deduction = 0.0; for(int i = 1; i 0) { return String.format(%s,

11. write a completed program based on

public boolean transactionFee(double fee) { double deduction = 0.0; for(int i = 1; i <= transactions; i++) { deduction += i * fee; } if(deduction < balance) { balance -= deduction; return true; } balance = 0.0; return false; }

12. write a completed program based on

public String toString() { if(balance > 0) { return String.format("%s, $%.2f", name, balance); } else if(balance < 0) { return String.format("%s, -$%.2f", name, -balance); } else { return name + ", $0.00"; } }

13. write a completed program based on

public void transfer(BankAccount account, double transfer) { if(transfer >= 5) { this.balance -= 5; if(this.balance >= transfer) { account.balance += transfer; this.balance -= transfer; } else if(this.balance - 5 < transfer) { account.balance += this.balance; this.balance = 0; } this.transactions++; account.transactions++; } }student submitted image, transcription available below

11. Suppose the following BankAccount class has been created / Each BankAccount object represents one user's account 2// information including name and balance of money public class BankAccount String name double balance; 6 public void deposit (double amount) balance balance amount; 10 public void withdraw(double amount) ( 12 13 14 balance = balance - amount; Add a field to the Bankaccount class named transactionFee for a real number representing an amount of nce to deduct every time the user withdraws money. The default value is $0.00, but the client can chan e transaction fee money during every withdraw call (but not from deposits). Make sure that the balane 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. 12. Add a tostring method to the BankAccount class from the previous exercise. Your method should return a stringha contains the account's name and balance separated by a comma and space. For example, if an account object named yana has the name "Yana" and a balance of 3.03, the call yana.tostring() should return the string "Yana, $3.03 13. Add a transfer method to the BankAccount class from the previous exercises. Your method should move monty from the current bank account to another account. The method accepts two parameters: a second BankAccount lo accept the money, and a real number for the amount of money to transfer. There is a $5.00 fee for transferring money, so this much must be deducted from the current account's balance before any transfer. The method should modify the two BankAccount objects such that "this" current object has its balance decreased by the given amour plus the $5 fee, and the other account's balance is increased by the given amount. If this account object does not bat enough money to make the full transfer, transfer whatever money is left after the $5 fee is deducted.If this accout modified De has under $5 or the amount is 0 or less, no transfer should occur and neither account's state should be m following are some example calls to the method BankAccount ben new BankAccount(); ben.deposit (80.00); BankAccount hal new BankAccount() hal .deposit (20.00); ben. transfer(hal, 20.00): /7 ben $55, hal $40 (ben -$25, hal +$20) ben.transfer (hal, 10.00 hal.transfer(ben, 60.00 ): // ben $40, hal $50 (ben -$15, hal +$10) ): // ben $85, hal $ 0 (ben +$45, hal -$50

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!