Question: Write a Java Program for below requirement( Please note: I need the answer according to the questions. Make it concise along with comment to understand.)

Write a Java Program for below requirement( Please note: I need the answer according to the questions. Make it concise along with comment to understand.)

Suppose you are given a class named BankAccount with the following contents:

// 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 an object with the given id/balance and 0 transactions.

public BankAccount(String id, double balance)

public double getBalance()

public String getID()

public String getTransactions()

// Adds amount to balance if between 0-500. Also counts as 1 transaction.

public void deposit(double amount)

// Subtracts amount from balance if user has enough money. Counts as 1 transaction.

public void withdraw(double amount)

...

}

1) Please write the method definitions for the above BankAccount Methods.

2) Write a method transactionFee to go in the BankAccount class. It takes a fee (real number) parameter and applies the fee to all past transactions.

The fee is applied once for the first transaction, 2x for the second, 3x for the third, etc. These fees are subtracted from the account's balance.

If the balance is large enough to afford all fees with > $0.00 remaining, the method returns true. If not, the balance is 0.0 and it returns false.

For example:

BankAccount savings = new BankAccount("Jimmy", 0.00);

savings.deposit(10.00);

savings.deposit(50.00);

savings.deposit(10.00);

savings.deposit(70.00); // balance = $140, with 4 transactions

savings.transactionFee(5.00); // deducts $5+10+15+20; balance = $90; returns true

savings.transactionFee(10.00); // deducts $10+20+30+40; balance = $0; returns false

3) Please create the class in one class file and then the testing (with main) in a separate class. Please test all methods for the class.

4) Please add comments as appropriate, and use good coding styles and nainge conventions as has been discussed in class.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!