Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(Programming problem 2) The Account.java (attached in this homework) contains a definition for a simple bank account class with methods to withdraw, deposit, get the

image text in transcribed
image text in transcribed
(Programming problem 2) The Account.java (attached in this homework) contains a definition for a simple bank account class with methods to withdraw, deposit, get the balance and account number, and print a summary. Save it to your directory and study it to see how it works. Then write the following additional code: (NOTE: you may want to modify Account.java) (a). Add a method public void transfer(Account acct, double amount) to the Account class that allows the user to transfer funds from one bank account to another. If acct/ and acct2 are Account objects, then the call acet.transfer(acet2,957.80) should transfer $957.80 from acetl to acct2. Be sure to clearly document which way the transfer goes! (b). Write a class Transfer Test with a main method that creates two bank account objects and enters a loop that does the following: - Asks if the user would like to transfer from account to account, transfer from account to accountl. or quit - If a transfer is chosen, asks the amount of the transfer, carries out the operation, and prints the new balance for each account. - Repeats until the user asks to quit, then prints a summary for each account. (e). Add a static method to the Account class that lets the user transfer money between two accounts without going through either account. You can (and should) call the method transfer just like the other one - you are overloading this method. Your new method should take two Account objects and an amount and transfer the amount from the first account to the second account. The signature will look like this: public static void transfer(Account acctl, Account acet], double amount) Modify your Transfer Test class to use the static transfer instead of the instance version. public class Account { private String name; private double balance; public Account() {} public Account(String name, double balance) { this.name = name; this.balance balance; } public void deposit(double amount) { balance = balance + amount; } public void withdraw(double amount) { balance balance - amount; } public double getBalance() { return balance; }

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

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions