Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Databases And Information Systems 1 International Baltic Conference Dbandis 2020 Tallinn Estonia June 19 2020 Proceedings

Authors: Tarmo Robal ,Hele-Mai Haav ,Jaan Penjam ,Raimundas Matulevicius

1st Edition

303057671X, 978-3030576714

More Books

Students also viewed these Databases questions

Question

6. Have you used solid reasoning in your argument?

Answered: 1 week ago