Question: Add a toString method to the BankAccount class from the previous exercise. Your method should return a string that contains the accounts name and balance

Add a toString method to the BankAccount class from the previous exercise. Your method should return a string that 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".


Data from Previous Exercise

Suppose the following BankAccount class has been created:

1 // Each BankAccount object represents one user's account // information including name and balance of money. public class BankAccount { 4 String name; double balance; public void deposit (double amount) { 8 balance = balance + amount; 9. 10 11 public void withdraw (double amount) { 12 balance =

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.

1 // Each BankAccount object represents one user's account // information including name and balance of money. public class BankAccount { 4 String name; double balance; public void deposit (double amount) { 8 balance = balance + amount; 9. 10 11 public void withdraw (double amount) { 12 balance = balance - amount; 13 } 14 LO

Step by Step Solution

3.37 Rating (163 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

public String tostring String result name hand... View full answer

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 Building Java Programs A Back to Basics Approach Questions!