Assignment 4 Details Essay

Submitted By Alex-Elcewicz
Words: 805
Pages: 4

Assignment #4: Arrays and ArrayLists
Due: Monday, March 16th @ 11:55PM
Total Possible Points: 20

How to Submit
Moodle assignment (no emails or hardcopies accepted)
Submit IDE project in zip or RAR format as or Assignment4.rar

To understand how to use arrays to store and retrieve data.
To understand how to use the ArrayList data structure to store and retrieve data.
To design and develop classes that model real-world entities

Your Task
In this assignment, you will write create three classes that serve as the start of a small banking system. Your program will use an array list to store transactions in a bank account, and an array to store bank accounts in a bank. You will also make use of iterative algorithms to help you complete various tasks – namely entering bank account information, finding a particular bank account, and computing the average size of a transaction.
(*) Feel free to reuse the code of the Bank and BankAccount classes in the package of the BIG JAVA sample code. Make sure you delete methods that you are not using!

Create a new NetBeans project named CS218 Assignment 4. Be sure to uncheck “Create Main Class” during the project setup. Create a new package named bank. All three (3) classes described below belong in the bank package.

1. Implement a BankAccount class (6 points total)
Three (3) private instance variables: int accountNumber double balance
ArrayList<Double> transactions
One (1) constructor: (2 points)
BankAccount(int acctNumber, double initBalance) – initializes the class’ instance variables, using the parameter variable values appropriately
Assigns a new ArrayList object to transactions. Don’t forget to add an import statement above your class to link the java.util.ArrayList library to your code.
Adds a transaction to transactions…think of initBalance as the amount of the initial deposit.
Five (5) public methods: int getAccountNumber() – returns the account number double getBalance() – returns the balance void deposit(double amount) – adds money to the account; adds a new transaction to the array list of transactions (1 point) void withdraw(double amount) – subtracts money from the account; adds a new transaction to the list of transactions (withdrawal amount should be added as a negative number) (1 point) double getAverageTransactionSize() – returns the average of the absolute values of all transaction amounts on the account. (2 points)
Uses a for-each loop in the calculation
Uses the Math.abs(double num) function to get the absolute value of each transaction amount.
2. Implement a Bank class (6 points total)
Three (3) private instance variables:
BankAccount[] accounts final int SIZE – the size of the accounts array; assign a value of 1000 int numAccounts – the number of accounts in the accounts array
One (1) constructor: (0.5 point)
Bank() – no parameters, but initializes accounts with a new BankAccount array of size SIZE.
Four (4) public methods: void addAccount(int aNumber, double aBalance) (2 points)
Creates a new BankAccount with the account number aNumber and the balance aBalance.
Puts the new BankAccount into the accounts array after the last existing account
Updates the number of accounts.
BankAccount find(int aNumber) – finds and returns the BankAccount in the accounts array whose account number matches aNumber. If so such bank account…