Making lists is a routine activity in our daily lives. During the week we may make a list of things to be purchased over

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Making lists is a routine activity in our daily lives. During the week we may make a list of things to be purchased over

Post by answerhappygod »

Making lists is a routine activity in our daily lives. Duringthe week we may make a list of things to be purchased over theweekend. Or it may be a list of people we wish to invite fordinner. In its simplest form a list consists of a series of itemsordered sequentially. A simple list of names could look like:
1. Michael Jackson2. Tracy Chapman3. Taylor Swift 4. Paul McCartney5. Kishore Jumar
A phone list could look like (phone numbers have been masked):
1. Sachin G 98101XXX762. Ajay M 98210YYY453. Priya A 98110ZZZ324. Barry L 617XYZ23155. Deepak V 510ABC3216
And a more complex list - for example, a shopping list could looklike:
1. Tomato Ketchup - 2bottles of 1Kg2. Milk - 2 packs of 1 Litre3. Yellow Butter - 1 pack of 500 gms4. English Breakfast Tea - 1box of 100 teabags5. Strawberry Jam - 1 bottle of 500 gms
Note in each case there is a sequential ordering and each itemin any of the 3 lists above has a similar structure. The structureof the third list will require some thought to arrive at a genericstructure for a “grocery shopping item”.
## Challenge – Part 1
In this challenge you will use collections to implement a TextAnalyzer. In the current age of word processors, it is so simple tolook at the bottom of the screen and immediately come to know howmany words we have typed in our document. Or how many characters wehave used. How exactly is this done ? You will find out some of thebasic building blocks for yourself as you tackle thischallenge.
**Task 1** – Design a class called **Word** that can be used tostore details of a word that is read from a text file. Apart fromthe word itself, the class should have an attribute to store thenumber of times the same word occurs in the file. Defineappropriate constructors and getter & setter methods for thisclass.
**Task 2** – This task involves reading a text file and creatinga word list. Your word list will consist of objects of the type**Word** defined in Task 1. You should take care to ensure that noword is repeated in the list. Instead, if a word that alreadyexists in the list is found, simply increment the word count. Once,you have read all the words in the file, use a method called**showWordList()** to show all the words that have been found alongwith their frequency.
**Task 3** – Notice in the output displayed in Task 2, that thewords are not shown in any specific order. They are simplydisplayed in the order in which they were found in the file. Nowrefactor your program so that the word list is constructed in sucha way that the words are placed in alphabetical order starting withthe word “a” (if it exists in the file). Display this sorted wordlist.
**Task 4** – Write a method that shows the words in your wordlist in reverse alphabetical order. In other words, you will needto begin with the last word in your list and display its detailsfirst. And then come backwards and show all the words in thereverse order.
**Task 5** – Write an additional method called**showFrequentWords()** that reads your alphabetically sorted wordlist and displays the words in descending order of frequency i.e.the word with the highest frequency is listed first, then the wordwith the next highest frequency, etc. If 2 words have the samefrequency, they should be listed in alphabetical order.
**Note:** You can use the Java Collections API for thischallenge.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply