Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you help solve the following Programming problem in Java? This program builds a class to create, populate and search for items in different data

Can you help solve the following Programming problem in Java?
This program builds a class to create, populate and search for items in different data structures then compare the execution time of each implementation. This time you will compare HashMaps and TreeMaps.
Create a new class to the project in your IDE and the repository as you complete this assignment.
Write a Java program to read a text file and count the number of times each word occurs. Use a TreeMap to do this. Words are anything separated by white space.
Use a small data file for testing as you initially write your program. However, for the real time measurements, you need a large data file. Get a free book from Project Gutenberg. Make sure the .txt file is at least 200 Kbytes.
Remove all the commas, periods, question marks and exclamation points. Do not remove any other punctuation. It will cause funky counts on small text files but won't be a significant issue with large files.
As you read from a file, store the words in a List (you choose). You will use this List for the remainder of the assignment. This avoids timing problems when reading the same file multiple times in the same program.
All comparisons should be case insensitive, so that "Therefore" and "therefore" are counted as the same word.
Start your timer, create a TreeMap, and then use the TreeMap to count the number of occurrences of each word in the List. After your program has counted all the words, print the 5 most frequently occurring words that are longer than 6 characters and their number of occurrences. Then stop your timer and record the result. Don't print any other words besides the top 5.
Repeat the previous step but use a HashMap instead. Record your measurements.

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

More Books

Students also viewed these Databases questions