Question: RangeFilterTester.java import java.util.ArrayList; class RangeFilterTester { public static void main( String[] args) { ArrayList accounts = new ArrayList(); accounts.add(new BankAccount(1398723,900)); accounts.add(new BankAccount(1432561,9900)); accounts.add(new BankAccount(1584624,52)); accounts.add(new

Purpose: practice implementing an interface (Filter). Difficulty: Easy See the following files: 

RangeFilterTester.java

import java.util.ArrayList;

class RangeFilterTester
{
public static void main( String[] args)
{
ArrayList accounts = new ArrayList();
accounts.add(new BankAccount(1398723,900));
accounts.add(new BankAccount(1432561,9900));
accounts.add(new BankAccount(1584624,52));
accounts.add(new BankAccount(1856210,2300));
accounts.add(new BankAccount(1745382,213));
accounts.add(new BankAccount(1965432,603));
accounts.add(new BankAccount(1234567,12));

for (int i = 0; i < accounts.size(); i++)
{
System.out.println(accounts.get(i));
}
System.out.println("After Filtering:");

for (int i = 0; i < accounts.size(); i++)
{
if (accounts.get(i).inRange(100,  1000))
  System.out.println(accounts.get(i));
}

System.out.println("Expected:Account Number: 1398723 Balance: 900.0");
System.out.println("Account Number: 1745382 Balance: 213.0");
System.out.println("Account Number: 1965432 Balance: 603.0");
}
}


BankAccount.java

public class BankAccount implements Filter
{
private long   accountNumber;    
private double balance;
private static int numberOfAccounts = 0;

public BankAccount()
{
    accountNumber = 0;
    balance = 0;
    numberOfAccounts++;
}

public BankAccount(long accountNumber)
{
    this.accountNumber = accountNumber;
    balance = 0;
    numberOfAccounts++;
}

public BankAccount(long accountNumber, double initialBalance)
{
    this.accountNumber = accountNumber;
    balance = initialBalance;
    numberOfAccounts++;
}
public BankAccount(int accountNumber, double initialBalance)
{
    this.accountNumber = accountNumber;
    balance = initialBalance;
    numberOfAccounts++;
}

public static int getNumberOfAccounts()
{
return numberOfAccounts;
}

public double getBalance()
{
  return balance;
}

public void deposit(double amount)
{
   this.balance += amount;
}

public void withdraw(double amount)
{
   this.balance -= amount;
}

public void transfer(double amount, BankAccount targetAccount)
{
this.withdraw(amount);
targetAccount.deposit(amount);
}

public String toString()
{
return "Account Number: " + accountNumber + " Balance: " + balance;
}

//-----------Start below here. To do: approximate lines of code = 4
// Implement the necessary method such that class BankAccount implements the Filter interface
// check the balance instance variable of this bank account object to see if it is in range specified by
// the parameters. See Filter.java






//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}


Filter.java

// interface Filter filters out objects based on whether an (double) attribute of the object
// is within a specified range
public interface Filter
{
// method inRange returns true if the attribute is >= low and <= high, returns false otherwise
boolean inRange(double low, double high);
}


P.s: please besides the code, also include a screenshot of code, and the output to confirm code doesn't get edited out and the output satisfies the problem!!

Purpose: practice implementing an interface (Filter). Difficulty: Easy See the following files: RangeFilterTester.java * BankAccount.java (has todo) * Filter.java Approximate total lines of code required: 4

Step by Step Solution

3.44 Rating (160 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

RangeFilterTesterjava import javautilArrayList class RangeFilterTester public static void main String args ArrayList accounts new ArrayList accountsad... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!