Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Declare an interface Filter as follows: public interface Filter { boolean accept(Object x); } Write a method: public static ArrayList collectAll(ArrayList objects, Filter f) that

Declare an interface Filter as follows:

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

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

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

Then write a program that asks the user for input and output textfile names, reads all words from inputfile, puts them into an ArrayList, calls collectAll, and prints a list of the short words to the output file. (Note: I did this part, please do the one that's below in bold)

Write another program which uses the interface and method written above, but this time it writes the results to a binary file using UTF-8. Also, this time it will append to the file if it already exists. (I need code for this one, it uses the same method and interfaces but writes the results to a binary file using UTF-8.)

End text files with .txt, and binary files with .dat

Please provide the sample output.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions