Download presentation
Presentation is loading. Please wait.
Published byPriscilla Manning Modified over 9 years ago
1
Word Counter HW Copyright © 2012 Pearson Education, Inc.
2
Specification Create a WordCounter class with a constructor that takes a file name as a parameter The class should have one field: a HashMap to store word count information The constructor should call a private method, countWords, that takes the file name as a parameter, reads in the file and counts the word frequencies The class should contain a get method for each field, as well as a print method that takes an output file name as a parameter and prints out the map in the following format: word:frequency –Hint: if you can’t see the output file, right-click on the project & select “Refresh (F5)” When printing, the map should be sorted by either the word order or frequency (Hint: see Collections.sort) You should include the sample text file on Blackboard Copyright © 2012 Pearson Education, Inc.
3
Sample file: initial-test.txt Hello my name is.... My favorite food Orange foodfoodfood computers1234 2014 Copyright © 2012 Pearson Education, Inc. Input File: word:frequency ---------------------- food4 orange2 my2 hello1 is1 20141 name1 favorite1 computers12341 Should output frequencies:
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.