Tester
import java.util.ArrayList;
public class Tester {
public static void main(String[] args) {
ArrayList<BankAccount> accounts = new ArrayList<BankAccount>();
accounts.add(new BankAccount(101, 300.0));
accounts.add(new BankAccount(102, 500.0));
accounts.add(new BankAccount(103, 600.0));
accounts.add(new BankAccount(104, 100.0));
accounts.add(new BankAccount(105, 0.0));
accounts.add(new BankAccount(106, 700.0));
accounts.add(new BankAccount(107, 400.0));
accounts.add(new BankAccount(108, 200.0));
accounts.add(new BankAccount(109, 500.0));
accounts.add(new BankAccount(110, 200.0));
double atLeast = 7 * 100.0;
int result = 0;
for (BankAccount a : accounts)
if (a.getBalance() >= atLeast)
result++;
}
}
BankAccount.java
/**
A bank account has a balance that can be changed by
deposits and withdrawals.
*/
public class BankAccount
{
/**
Constructs a bank account with a zero balance.
*/
public BankAccount()
{
balance = 0;
}
/**
Constructs a bank account with a given balance.
@param initialBalance the initial balance
*/
public BankAccount(double initialBalance)
{
balance = initialBalance;
}
/**
Constructs a bank account with a zero balance
@param anAccountNumber the account number for this account
*/
public BankAccount(int anAccountNumber)
{
accountNumber = anAccountNumber;
balance = 0;
}
/**
Constructs a bank account with a given balance
@param anAccountNumber the account number for this account
@param initialBalance the initial balance
*/
public BankAccount(int anAccountNumber, double initialBalance)
{
accountNumber = anAccountNumber;
balance = initialBalance;
}
/**
Gets the account number of this bank account.
@return the account number
*/
public int getAccountNumber()
{
return accountNumber;
}
/**
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;
}
private int accountNumber;
private double balance;
}