I have an assignment where I am creating a BankAccount program. I have to create an ArrayList of BankAccounts and have the program ask the user how many accounts to create and then have a loop to ask the user for the accountId, name, and initial balance for each account and the add the bank account to the ArrayList. Below is what I have so far but I am stuck on how to do the loop to ask the user for the information and put it into the ArrayList.
BankAccount.java
public class BankAccount {
private int accountId;
private String name;
private double balance;
public BankAccount(int accountID, String personName, double initialBalance) {
accountId = accountID;
name = personName;
balance = initialBalance;
}
public void deposit() {
}
public void withdraw() {
}
public int getAccountId() {
return accountId;
}
public String getName() {
return name;
}
public double getBalance() {
return balance;
}
public String toString() {
return "BankAccount" + name + accountId + balance;
}
}
BankAccountTester.java
import java.util.ArrayList;
import java.util.Scanner;
public class BankAccountTester {
public static void main(String[] args) {
BankAccount b = new BankAccount(int accountID, String name, double initialBalance);
int n = 0;
int count;
ArrayList<String> bankAccounts = new ArrayList<String>(n);
Scanner in = new Scanner(System.in);
System.out.print("How many accounts are you going to enter? ");
n = in.nextInt();
for (int i = 0; i < n; i++)
{
System.out.print("Enter the account name: ");
String name = in.next();
System.out.print("Enter the account number: ");
int assignment = in.nextInt();
System.out.print("Enter the initial balance: ");
double balance = in.nextInt();
System.out.println(b.toString);
}
}
}