I need help on a programming assignment. The class of BankAccount already exists and works as it should. I have never been asked to place objects into arrays before, and am having trouble doing so.
I have started with the following:
public class Bank
{
private BankAccount[] Bank;
public Bank(BankAccount[] Bank)
{
BankAccount[] b1 = new BankAccount[10];
}
Although it compiles, it is wrong. I am not sure where to go.
The following are the requirements of the code that I am currently stuck on.
- An object of class Bank can hold up to 10 BankAccount objects.
- The constructor for the Bank object will create an array that can hold up to 10 BankAccount objects.
The following code is the test program that our professor included with the assignment that we must use:
System.out.println("\nCreate bank1");
Bank bank1 = new Bank();
System.out.println("\nOne account");
BankAccount b1 = new BankAccount("Joe Mac", 1234);
b1.adjust(1000.0);
bank1.addAccount(b1);
bank1.printAccounts();
System.out.println("\nTwo accounts");
BankAccount b2 = new BankAccount("Sally Ride", 2345);
b2.adjust(2000.0);
bank1.addAccount(b2);
bank1.printAccounts();
System.out.println("\nThree accounts");
BankAccount b3 = new BankAccount("Pat Armstrong", 3456);
b3.adjust(3000.0);
bank1.addAccount(b3);
bank1.printAccounts();
System.out.println("\nMonthly Fee");
bank1.monthlyFee(fee);
bank1.printAccounts();
System.out.println("\nErrors:");
Help would be immensely appreciated. Thank you.