Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help to finish this project!! 11. Suppose the following BankAccount class has been created: 1 // Each BankAccount object represents one user's account

I need help to finish this project!!

11. Suppose the following BankAccount class has been created: 1 // Each BankAccount object represents one user's account 2 // information including name and balance of money. 3 public class BankAccount { 4 String name; 5 double balance; 6 7 public void deposit(double amount) { 8 balance = balance + amount; 9 } 10 11 public void withdraw(double amount) { 12 balance = balance - amount; 13 } 14 } Add a field to the BankAccount class named transactionFee for a real number representing an amount of money to deduct every time the user withdraws money. The default value is $0.00, but the client can change the value. Deduct the transaction fee money during every withdraw call (but not from deposits). Make sure that the balance cannot go negative during a withdrawal. If the withdrawal (amount plus transaction fee) would cause it to become negative, dont modify the balance at all. 12. Add a toString method to the BankAccount class from the previous exercise. 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 yana has the name "Yana" and a balance of 3.03, the call yana.toString() should return the string "Yana, $3.03". 13. Add a transfer method to the BankAccount class from the previous exercises. Your method should move money from the current 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 accounts 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 account's balance is increased by the given 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. The following are some example calls to the method: BankAccount ben = new BankAccount(); ben.deposit(80.00); BankAccount hal = new BankAccount(); hal.deposit(20.00); ben.transfer(hal, 20.00); // ben $55, hal $40 (ben -$25, hal +$20) ben.transfer(hal, 10.00); // ben $40, hal $50 (ben -$15, hal +$10) hal.transfer(ben, 60.00); // ben $85, hal $ 0 (ben +$45, hal -$50)

Design Considerations for Project

1. You must design your "BankAccount" class such that it will satisfy the requirements stated in the three text problems. The supplied Client program will invoke the required class, non-static methods described in the text and in the Project Description document (Note the additional, required method, "name()".

2. The supplied Client program creates 3 different "BankAccount" objects. You should notice that each takes different number of arguments. Therefore, you will need to supply at least 3 Constructors for the class. You are to make sure that proper values are passed to the Constructors you define, i.e. the starting balance and transaction fee must be greater than or equal to 0.0. Also note that unless supplied in a Constructor, the transaction fee is set to the specified "default" value of 0.0....hint a Class static constant (final) value.

3. For Class method "deposit" you must enforce the invariant condition that a deposit amount must be greater than 0.0. The same goes for a withdrawal and transfer amount supplied to methods "withdraw" and "transfer".

4. For a "withdraw", the transaction can be completed iff (if and only if) the specified withdraw amount PLUS the transaction fee is >= the current balance.

5. You are to keep an accumulated total of all fees charged to the account; i.e. update this amount each time the "withdraw" and "transfer" methods are called.

6. For a transfer, there is fixed, constant fee of $5.00. Note that this is a different fee than the transaction fee that applies to a withdrawal. The transfer can only occur if the current balance of the invoking "BankAccount" object exceeds $5.00. If the account balance exceeds $5.00 but is less than the requested transfer amount plus the $5.00 fee, a partial transfer can occur that leaves the invoking object's balance as exactly $0.00. Only the allowed transfer amount is "deposit"ed to the target account, the "BankAccount" object reference passed to the "transfer" method.

7. You will need to provide an overridden "toString()" method as specified in Exercise #12. In addition to the format specified in the exercise, you are to include the total accumulated fees charged, see my sample output.

8. You are free to use class private "helper" method(s) to implement your method designs. A good example would be methods(s) to enforce the invariant conditions.

BankAccount.java:

public class BankAccount { // Public Interface // 1. Constructors // Add your Constructor(s) here......

// 2. Mutator Methods // A. boolean deposit(double) // Note: This method enforces the class invariant that stipulates // that a deposit amount MUST be > $0.00 public boolean deposit(double depositAmount) { boolean depositMade = false; // Insert your code here. Remember, you MUST enforce the invariant condition!!! return depositMade; } // // B. boolean withdraw(double) // Note: This method enforces the class invariant that stipulates // that the ending account balance MUST be >= $0.00 public boolean withdraw(double withdrawalAmount) { boolean withdrawalMade = false; // Insert your code here. Remember, you MUST enforce the invariant condition!!! return withdrawalMade; } // // C. double transfer(BankAccount,double) // RETurns the amount transferred: 0.0 - No transfer occurred public double transfer(double withdrawalAmount) { double amountTransfered = 0.0; // Create your method here

return amountTransfered; } // // // 3. Virtual (late binding) Methods: Extensions of class "Object" // A. toString() // Constructs Description "String" of the object String toString() { String str = ""; // Insert your code here..... return str; }

// Class Private, non-static Data Members // Private Class Data Members // 1. Variable Declarations private String name; private double 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

Advanced MySQL 8 Discover The Full Potential Of MySQL And Ensure High Performance Of Your Database

Authors: Eric Vanier ,Birju Shah ,Tejaswi Malepati

1st Edition

1788834445, 978-1788834445

More Books

Students also viewed these Databases questions

Question

=+How should it be delivered?

Answered: 1 week ago

Question

=+4 How does one acquire a global mindset?

Answered: 1 week ago