Exercise 3. BankAccount Consider the Java class BankAccount.java. The BankAccount class contains as instance variables t
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Exercise 3. BankAccount Consider the Java class BankAccount.java. The BankAccount class contains as instance variables t
Exercise 3. BankAccount Consider the Java class BankAccount.java. The BankAccount class contains as instance variables the following fields: • String id: the name of the owner of the bank account double balance: the amount of money in the bank account int transactions the number of transactions that have been performed by this user An array list of transactions You are required to implement the fo e following methods: • Bank Account(String id): Constructor. Constructs a Bank Account object with the given id, with o balance and transactions double getBalance(): returns the value of the balance field. String geldo: returns the value of the id field int getTransactions : returns the value of the transactions field. It will display the list of transactions, • void deposit(double amount): Adds the amount to the balance if it is between 0-500. This counts as I transaction. And the transaction should be added to the list as: "Deposit of Samount • void withdraw/double amount): Subtracts the amount from the balance if the user has enough money. If not, it should print as such. This counts as I transaction. It should be added to the list of transaction as: "Withdraw of Samount": • String toString(): returns the bank account as a String in the following format: <id>, S<balance> For example, if the account has an id "Mary" and a balance of " 17.5" it should be returned as Mary, $517.50. The balance should always have 2 digits after the decimal • boolean transaction Feeſdouble amount): accepts a fee amount as a parameter and applies that fee to the user's past transactions. The fee is applied once for the first transaction, twice for the second transaction, three times for the third, and so on. If the user's balance is large enough to afford all of the fees with greater than 0.00 remaining, the method returns true. If the balance cannot afford all of the fees or has no money left the balance is left as 0 and the method return false void transfer(Bank Account acc, double amount): The method accepts two parameters: a second Bank Account to accept the money, and a double for the amount of money to transfer. There is a $5.00 fee for transferring money that will be deducted from the sender's account. The method deducts from "this" current object the given amount plus the S5 fee, and the other Bank Account's balance is increased by the given amount. A transfer also counts as a transaction on both accounts. If after deducting the $5.00, "this account doesn't have enough to complete the transaction, as much money as possible is transferred to acc. If the account has less than $5.00, the no transfer should occur and neither accounts change.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!