OutPut is supposed to be: Size: 3
first account number is 1008
last account number is 1729
Sub
import java.util.ArrayList; public class BankAccount2{ public BankAccount2(int anAccountNumber) { accountNumber = anAccountNumber; balance = 0; } public BankAccount2(int anAccountNumber, double initialBalance){ accountNumber = anAccountNumber; balance = initialBalance; } public int getAccountNumber(){ return accountNumber; } public void deposit(double amount){ double newBalance = balance + amount; balance = newBalance; } public void withdraw(double amount){ double newBalance = balance - amount; balance = newBalance; } public double getBalance(){ return balance; } private int accountNumber; private double balance; }
Main
This program is in my notebook, was testing professor's program but it isn't functioning..public class ArrayListTester { public static void main(String[] args) { ArrayList<BankAccount2> accounts = new ArrayList<BankAccount2>(); accounts.add(new BankAccount2(1001)); accounts.add(new BankAccount2(1015)); accounts.add(new BankAccount2(1729)); accounts.add(1,new BankAccount2(1008)); accounts.remove(0); System.out.println("size" + accounts.size()); BankAccount2 first = accounts.get(0); System.out.println("first account number is: " + first.getAccountNumber()); BankAccount2 last = accounts.get(accounts.size()-1); System.out.println("last account number is: " + last.getAccountNumber()); } }