Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

BankAccount - transfer Language / Type: S Java classes instance methods Related Links: BankAccount.java Suppose that you are provided with a pre - written class

BankAccount-transfer
Language/Type:
S Java classes instance methods
Related Links:
BankAccount.java
Suppose that you are provided with a pre-written class BankAccount as shown below. (The headings are shown, but not the method bodies, to save space.) Assume that the fields, constructor, and methods shown are already implemented. You may refer to them or use them in solving this problem if necessary.
Write a method named transfer that will be placed inside the BankAccount class to become a part of each BankAccount object's behavior. The transfer method moves money from this bank account to another account. The method accepts two parameters: a second BankAccount to 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 amount plus the $5 fee, and the other BankAccount object's balance is increased by the given amount. A transfer also counts as a transaction on both accounts.
If this account object does not have enough money to make the full transfer, transfer whatever money is left after the $5 fee is deducted. If this account has under $5 or the amount is 0 or less, no transfer should occur and neither account's state should be modified.
// A BankAccount keeps track of a user's money balance and ID,
??? and counts how many transactions (deposits/withdrawals) are made.
public class BankAccount {
private String id;
private double balance;
private int transactions;
// Constructs a BankAccount object with the given id, and
//O? balance and transactions.
public BankAccount (String id)
// returns the field values
public double getBalance()
public String getID()
public String getTransactions()
// Adds the amount to the balance if it is between O-5OO??.
// Also counts as 1 transaction.
image text in transcribed

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_2

Step: 3

blur-text-image_3

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

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions