Question: BankAccount - toString Language / Type: Java classes instance methods Related Links: BankAccount.java String Math Add the following method to the BankAccount class: public String

BankAccount-toString
Language/Type:
Java classes instance methods
Related Links:
BankAccount.java String Math
Add the following method to the BankAccount class:
public String tostring()
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 benben has the name "Benson" and a balance of 17.25, the call of benben, tostring() should return:
Benson, $17.25
There are some special cases you should handle. If the balance is negative, put the - sign before the dollar sign. Also, always display the cents as a two-digit number. For example, if the same object had a balance of -17.5, your method should return:
Benson, -$17.50
Your code is being added to the following class:
public class BankAccount {
private String name;
private double balance:
//// your code goes here
 BankAccount-toString Language/Type: Java classes instance methods Related Links: BankAccount.java String Math

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!