Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

a Java class called BankAccount (Parts of the code is given below), which has two private fields: name (String) and balance (double), and three methods:

a Java class called BankAccount (Parts of the code is given below), which has two private fields: name (String) and balance (double), and three methods: deposit(double amount), withdraw(double amount) and toString(). Write the necessary constructors, accessor methods and mutator methods. The deposit() method adds the amount to the account causing the current balance to increase, withdraw() method subtracts the amount causing the current balance to decrease and toString() method should return the name and the current balance separated by a comma. For example, if you print out the object with name Jake and balance 40.0 then it should print:

Jake, $40.00

public class BankAccount {

private String name;

public void deposit(double amount) {

balance = balance + amount;

}

public void withdraw(double amount) {

balance = balance amount;

}

public BankAccount(){};

public BankAccount(String name_new, double bal_new) {

}

...

}

Write a client program called BankAccountClient that creates a BankAccount object called B1 and initializes name and balance at the time of instantiating the object using the default constructor. Call the deposit() method to add $500 to this account and call the toString() method to print the current balance using System.out.println() from the main(). Next, call the withdraw() method to subtract $300 from this account and print B1 using System.out.println() from the main(). Create another object called B2 without initializing it and display the name and current balance for this object using System.out.println(). Finally, use the accessor/mutator methods to assign name and balance to B2. Print the object B2, using System.out.println().

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual C# And Databases

Authors: Philip Conrod, Lou Tylee

16th Edition

1951077083, 978-1951077082

More Books

Students also viewed these Databases questions

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago