Menu

[Solved] P917 Java Please Explain Well Declare Interface Filter Follows Public Interface Filter Boo Q37277027

P9.17 (For Java, and can you please explain aswell.)

Declare an interface Filter as follows:

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

Write a method: public static ArrayList collectAll(ArrayListobjects, Filter f) that returns all objects in the objects listthat are accepted by the given filter.

Provide a class ShortWordFilter whose filter method accepts allstrings of length < 5.

Then write a program that asks the user for input and outputtextfile names, reads all words from an input file, puts them intoan ArrayList, calls collectAll, and prints a list of the shortwords to the output file.

Expert Answer


Answer to P9.17 (For Java, and can you please explain as well.) Declare an interface Filter as follows: public interface Filter { … . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *