Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Having trouble solving this problem: Any help is appreciated :) 8. Classes and Objects // A BankAccount keeps track of a Suppose that you are

Having trouble solving this problem:

image text in transcribed

Any help is appreciated :)

8. Classes and Objects // A BankAccount keeps track of a Suppose that you are provided with a pre-written class // user's money balance and ID (name), BankAccount as described at right. (The headings are shown, but and counts how many transactions not the method bodies, to save space.) Assume that the fields, constructor, and methods shown are already implemented You public class BankAccount may refer to them or use them in solving this problem if necessary // (deposits/withdrawals) are made private String id; private double balance private int transactions Write an instance 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 Constructs a BankAccount // object with the given id, and // $0 balance and 0 transactions. public BankAccount (String id) // returns the field values public double getBalance () public String getID) public int getTransactions ) There is a S5.00 fee for transferring money, so this much must be deducted from the current account's balance before any transfer // Adds the amount to the balance // if it is between 0-500 The method should modify the two BankAccount objects such that ALso counts as 1 transaction this" current object has its balance decreased by the given amouublic void deposit(double amount) plus the $5 fee, and the other BankAccount object's balance is increased by the given amount. A transfer also counts as a// the balance if the user has transaction on both accounts Subtracts the amount from // enough money. / Also counts as 1 transaction public void withdraw (double amount) 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. your method would go here For example, given the following BankAccount objects BankAccount benson new BankAccount ("Benson") benson.deposit (90.00) BankAccount martin new BankAccount ("Marty" martin.deposit (25.00) Assuming that the following calls were made, the balances afterward are shown in comments to the right of each call benson.transfer (martin, 20.00)IIB$65, M $45 (B loses $25, M gains $20) benson.transfer (martin, 10.00) B $50, M $55 (B loses $15, M gains $10) benson.transfer (martin,-1) martin.transfer (benson, 39.00)// B $89, M$11 (M loses $44, B gains $39) martin.transfer (benson, 50.00)17 B $95, M$0 (M loses $11, B gains 6) martin.transfer (benson, 1.00) IB $95, M no effect: no money in acct) benson.transfer (martin, 88.00) 1 B 2, M $88 (B loses $93, M gains $88) benson.transfer (martin, 1.00) IIB2, M $88 (no effect: can't afford fee) // B $50, M $55 (no effect; negative amount)

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

Database Processing Fundamentals Design

Authors: Marion Donnie Dutton Don F. Seaman

14th Edition Globel Edition

1292107634, 978-1292107639

More Books

Students also viewed these Databases questions