CECS 277 – Lab 10 – Maps solution

$30.00

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (1 vote)

Word Frequency

Create a program that keeps track of the frequency of each of the words in a text file
(words.txt) by using a TreeMap. Allow the user to search for a particular word with its
frequency or to display all of the words with their frequencies. Repeat the program until
the user quits.

Methods:
1. readFile – passes in a filename as a String. Construct and return the map
populated with each of the words in the file and the number of times each one
appeared. Each time you come across a duplicate word, get the old value,
increment it, and put it back in the map.

2. search – pass in the map. Prompt the user to enter a String. Display the word
with its frequency in the format ‘word => frequency’ (ex. Alice => 2). If the
word is not in the map, display it in the same format with a 0.

3. display – pass in the map. Display each of the words in the map with their
frequencies where each word is displayed in the format ‘word => frequency’.
(note: since the map is a TreeMap, it will automatically display in sorted order)

4. menu – display the menu below to prompt the user to enter a menu option, then
return the user’s valid input (you can use getIntRange method of the
CheckInput class provided on Beachboard).

Example Output (user input is in italics):
1. Search
2. Display
3. Quit
1
Enter word: sister
sister => 2
1. Search
2. Display
3. Quit
1
Enter word: hello
hello => 0
1. Search
2. Display
3. Quit
3

Notes:
1. Map methods: https://docs.oracle.com/javase/7/docs/api/java/util/Map.html
2. Add Javadocs and other brief comments to your program to describe your code.
3. Thoroughly test your program before submitting.