Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[Java] In this problem you will implement a solution using the design pattern for collecting objects. We are going to model a bank. A Bank

[Java]

In this problem you will implement a solution using the design pattern for collecting objects. We are going to model a bank. A Bank uses an ArrayList to keep track of BankAccountobjects. You will write the Bank class

The BankAccount class is provided for you. A BankAcount has a balance and a accountId.

A Bank has a constructor that takes no parameters. It needs to initialize the ArrayList used to collect bankAccounts

It has methods

add adds the specified BankAccount to the Bank

largestFirst puts the BankAccount with the largest balance first in the list. If two have the same large balance, use the first one encountered in the list

contains determines if a BankAccount with a given accountId is in the Bank. Return true is so, otherwise false

list gets an ArrayList of the BankAccount accountIds in the Bank that have balances over the specified amount.

list gets an ArrayList of the BankAccount accountIds in the Bank

Use the following files:

BankAccount.java

/** A bank account has a balance that can be changed by deposits and withdrawals. */ public class BankAccount { private double balance; private String accountId; /** Constructs a bank account with a given balance. @param initialBalance the initial balance @param id the id for this account */ public BankAccount(double initialBalance, String id) { balance = initialBalance; accountId = id; } /** * Gets the id for this account * @returns the id for this account */ public String getAccountId() { return accountId; } /** Deposits money into the bank account. @param amount the amount to deposit */ public void deposit(double amount) { balance = balance + amount; } /** Withdraws money from the bank account. @param amount the amount to withdraw */ public void withdraw(double amount) { balance = balance - amount; } /** Gets the current balance of the bank account. @return the current balance */ public double getBalance() { return balance; } } 

BankTester.java

public class BankTester { public static void main(String[] args) { Bank accounts = new Bank(); //test empty bank accounts.largestFirst(); System.out.println(accounts.list()); System.out.println("Expected: []"); accounts.largestFirst(); System.out.println(accounts.list()); System.out.println("Expected: []"); System.out.println(accounts.contains("abc123")); System.out.println("Expected: false"); System.out.println(accounts.list(10000)); System.out.println("Expected: []"); accounts.add(new BankAccount(10000.0, "def333")); accounts.add(new BankAccount(20000.0, "abc123")); accounts.add(new BankAccount(15000.0, "pqr456")); accounts.add(new BankAccount(20000.0, "xyz789")); accounts.add(new BankAccount(9500.0, "abc111")); accounts.largestFirst(); System.out.println(accounts.list()); System.out.println("Expected: [abc123, def333, pqr456, xyz789, abc111]"); System.out.println(accounts.contains("abc123")); System.out.println("Expected: true"); System.out.println(accounts.contains("aaa999")); System.out.println("Expected: false"); System.out.println(accounts.list(10000)); System.out.println("Expected: [abc123, pqr456, xyz789]"); System.out.println(accounts.list(100000)); System.out.println("Expected: []"); // accounts.add(); } } 

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

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Sham Navathe

4th Edition

0321122267, 978-0321122261

More Books

Students also viewed these Databases questions

Question

=+2. Identify and analyze your audience.

Answered: 1 week ago

Question

5-4 What are the current computer software platforms and trends?

Answered: 1 week ago