For a video version of this lab, watch these on the static keyword (https://www.youtube.com/watch?v=tj3q7eVHU3M and https://www.youtube.com/watch?v=lgbQebgKH5w ).
This lab will be due on Monday, November 17th at 11:59 pm.
Create a public class BankAccount. Each object of this class will represent a specific account at your bank. Your class should have the following variables:
Non-static variables (make these private):
-a String representing the name of the owner of the account
-an int representing how much money is in the account
-a boolean representing whether or not the account is open (this will be true if the account is open, false if it is closed)
Static variables (make these public. Remember to set up an initial value for each of these):
-an int counting how many open accounts there are
-an int counting the total amount if money in the bank across all of the accounts
-an int counting how many transactions (deposits and withdrawals) have been made
Write the following non-static methods in your classes:
BankAccount(String inputName, int startAmount) - this constructor should initialize the name and account balance to be the inputs and set the account to be open. It should also correctly update the static variables tracking how many open accounts there are and the total money in all accounts.
withdraw - If the account is open, this void method inputs an int, then subtracts that much money from the balance of the account. This should correctly update the static variables for total amount of money and number of transactions as well. If the account is closed (or the amount of money they try to withdraw is more than the amount in the account), this method should do nothing.
deposit - If the account is open, this void method inputs an int, then adds that much money to the balance of the account. This should correctly update the static variables for total amount of money and number of transactions as well. If the account is closed, this method should do nothing.
close() - this void method takes no inputs and should change the account status to be closed. It should set the balance of that account to be 0 and update the static variables for the total amount of money and number of open accounts appropriately as well. Closing an account does NOT count as a transaction. (note that once an account is closed, it cannot be reopened later).
getBalance() - this accessor method takes no inputs and returns the int representing the current balance of the account.
Write the following STATIC methods in your class:
getOpenAccounts() - these three accessor methods take no inputs and return an int representing the appropriate static variable
getTotalMoney()
getTransactions()
donate(int x) - this void method inputs an int representing a new amount of money donated to the bank. It should add that amount to the total amount of money in the bank and make no other changes.
Create a BankDriver class. This class will have one static main method. In this method, you will create at least three bank accounts and call each of the methods at least once. Here is an example of what this might look like and what the values are of the static variables:
//bank now has 0 accounts, 0 total money, 0 transactions
BankAccount a = new BankAccount("borish", 200);
BankAccount b = new BankAccount("gravel", 300);
BankAccount c = new BankAccount("meza", 1000);
//bank should now have 3 accounts, 1500 total money, 0 transactions
a.deposit(50);
a.withdraw(150);
//bank now has 3 accounts, 1400 total money, 2 transactions
a.close();
//bank now has 2 accounts, 1300 total money, 2 transactions
a.deposit(500); //since a is closed, this should do nothing
b.deposit(500);
c.deposit(500);
c.withdraw(100);
//bank now has 2 accounts, 2200 total money, 5 transactions
BankAccount.donate(1000);
//bank now has 2 accounts, 3200 total money, 5 transactions
Create a public class MoreArray, which will contain four STATIC methods that review different array topics.
bankSum(BankAccount[] moneys) - this method inputs an array of BankAccounts and returns an int. It should return the sum of the balances in all of the accounts in the input array.
startEnd(String[] words, String term) - this method inputs an array of Strings, and a single string. It should return an int counting how many of the entries in words begin OR end with term. For example, if you send this method the array {"walking", "king george", "no", "hello king", "yes king yes", "baking king"} and term is "king" it should return 4 (for "walking", "king george", "hello king" and "baking king"). Make sure to avoid out of bounds errors if the String is too short - indexof might be good for this.
rowsAdd(int[][] arr, int input) - this method will input a 2d array of ints, then return an int counting how many of the rows of that 2d array add up to the other input value. For example, if you have the 2d array { {2,3,4}, {5,1,3}, {0,0,5}, {2,9,-2} } and you send this method that array and the input value of 9, it should return 3 (for rows 0,1, and 3).
colsAdd(int[][] arr, int input) - this method will input a 2d array of ints, then return an int counting how many of the COLUMNS of that 2d array add up to the other input value. For example, if you have the 2d array { {2,3,4}, {5,1,3}, {0,0,5}, {2,9,-2} } and you send this method that array and the input value of 9, it should return 1 (for column 0).
Make sure to test these methods in main or by entering them directly into bluej!
Submit BankAccount.java, BankDriver.java, and MoreArray.java