I'm making a a program for class. So far i have 1-3 done but i cant figure how to implement 4 and 5. I have been stuck on this for awhile. There are two classes that must be used.
- how many bank accounts are in the bank
2) Make a new array to hold the specified number of BankAccounts
3) In a loop, ask the user for the bank account number and balance, construct a BankAccount object with the account number and balance, and put the new BankAccount object in the array
4) After the user has entered all the bank accounts, use a for loop (or a for each loop) to compute the total balance of the accounts in the array
5) Print the computed total balance of the accounts and the average balance.
package Hw2;
import java.util.Scanner;
import java.util.ArrayList;
public class BankArrayTester {
public static void main(String[] args){
      Scanner in = new Scanner(System.in);
      System.out.println("Please enter the number bank accounts:");
      int accounts= in.nextInt();
      BankAccount [] accountinfo = new BankAccount [accounts];
      int c=0;
      while(c<accounts){
          c++;
         System.out.println("Enter account number for account "+c);
        int number=in.nextInt();
        System.out.println("Enter balance for account "+c);
        double balance=in.nextDouble();
        int a=0;
        BankAccount numberbalance = new BankAccount(number,balance);
        accountinfo [a]=numberbalance;
        double test1;
        for (int i = 0; i < accountinfo.length; i++) {
            test1 = accountinfo[a].getBalance(); 
            System.out.println(test1);
        }
      }
    }
}
other class
    package Hw2;
     /**
     A bank account has a balance that can be changed by 
   deposits and withdrawals.
  */
  public class BankAccount
  {
    private double balance;
    private int accountNumber;
/**
   Constructs a bank account with a zero balance.
*/
public BankAccount(int _accountNumber)
{   
   balance = 0;
}
/**
   Constructs a bank account with a given balance.
   @param initialBalance the initial balance
*/
public BankAccount(int _accountNumber, double initialBalance)
{   
   accountNumber = _accountNumber;
   balance = initialBalance;
}
/**
   Deposits money into the bank account.
   @param amount the amount to deposit
*/
public void deposit(double amount)
{  
   double newBalance = balance + amount;
   balance = newBalance;
}
/**
   Withdraws money from the bank account.
   @param amount the amount to withdraw
*/
public void withdraw(double amount)
{   
   double newBalance = balance - amount;
   balance = newBalance;
}
/**
   Gets the current balance of the bank account.
   @return the current balance
*/
public double getBalance()
{   
   return balance;
}
}
/**
   Gets the account number of the bank account.
   @return the account number
*/
 
     
    