Question: In Exercise P9.16, add a method to the Filter interface that retains all objects accepted by the filter and removes the others: static void retainAll(Object[]

In Exercise P9.16, add a method to the Filter interface that retains all objects accepted by the filter and removes the others: static void retainAll(Object[] values, Filter condition)


Data from Exercise P9.16,

Declare an interface Filter as follows:

public interface Filter { boolean accept(Object x); }

Add a Filter parameter to the average method of Section 9.6. Only objects that the filter accepts should be processed.  Demonstrate your modification by processing a collection of bank accounts, filtering out all accounts with balances less than $1,000.

Step by Step Solution

3.44 Rating (160 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Heres an example implementation of the modified Filter interface ... 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 Java Concepts Late Objects Questions!