Create an array to store letter frequency counts

Assignment Help JAVA Programming
Reference no: EM131585902

Create a class LetterCount that:

1) stores a single character (a letter) and a count (an integer) in private variables

2) implements the Comparable interface, thus there must be a compareTo() method which should compare two LetterCount objects by their count values

3) overrides toString() with a printable representation that shows the letter and the count
Second, create a program with a main() method that:

1) Asks the user for a filename of a text file (assumed to be in the same directory) and create a Scanner to read from it. Your program should use try-catch blocks to re-prompt the user if the file name is invalid.

2) Create an array to store letter frequency counts (# of a's, # of b's, # of c's, etc.). Then, read in the entire specified file and count the number of each letter seen. Ignore all punctuation and count lowercase and capital letters the same (x or X each count the same).

3) Create a LetterCount object for each letter and corresponding frequency count and put all of these objects in an array.

4) Use Arrays.sort() to sort the LetterCount objects. Then use a for-loop to print out all the LetterCount objects from the array, in reverse, so that we can see the frequency of each letter from the file, in order of frequency (from most to least frequent)

Notes:
+ the compareTo() method in LetterCount should return -1 if "this" LetterCount has a smaller count than ther "other" LetterCount, given by the argument to the method. It should return 0 if they're equal, and return 1 otherwise.
+ To read from the file, use a while-loop with the hasNext() method of the Scanner on the file. Then read it in to a String variable, one line at a time, using the nextLine() method. Then, process this String one character at a time using a for-loop and the charAt() method
+ one way to do the letter counting: set up a String of all the letters: "abcdefghijklmnopqrstuvwxyz" and use the indexOf() method on this String to look up a letter from the alphabet. If the indexOf() value is -1, the character is NOT a letter so ignore it. If it is not -1, use the index given to increment the count in an array of 26 int values (each representing the count of the corresponding letter)

To test your program you can use the attached text file, wonderland.txt. The output should be:
Letter e was seen 15395 times.
Letter t was seen 12200 times.
Letter a was seen 9802 times.
Letter o was seen 9477 times.
Letter i was seen 8633 times.
Letter n was seen 8051 times.
Letter h was seen 7889 times.
Letter s was seen 7268 times.
Letter r was seen 6610 times.
Letter d was seen 5469 times.
Letter l was seen 5211 times.
Letter u was seen 3978 times.
Letter c was seen 3000 times.
Letter w was seen 2952 times.
Letter g was seen 2943 times.
Letter y was seen 2584 times.
Letter m was seen 2467 times.
Letter f was seen 2382 times.
Letter p was seen 1968 times.
Letter b was seen 1746 times.
Letter k was seen 1290 times.
Letter v was seen 963 times.
Letter j was seen 235 times.
Letter q was seen 220 times.
Letter x was seen 176 times.
Letter z was seen 80 times.

Attachment:- wonderland.rar

Reference no: EM131585902

Questions Cloud

Terms of product manufacture and marketing : Cultural considerations in terms of product manufacture and marketing; in other words, what types of modifications in terms of "go global act local
How much will you need to deposit each year : You have been in the workforce for a year or two now and are keen on buying your first house. how much will you need to deposit each year?
Describing the instruments application in counseling : Describing the instrument's application in counseling.How the test results are interpreted and used in diagnosis and treatment.
How are camera angles used within your film : How are camera angles used within your film? Be sure to point to two specific scenes. Discuss how your film is framed. Discuss one scene and depth of field.
Create an array to store letter frequency counts : implements the Comparable interface, thus there must be a compareTo() method which should compare two LetterCount objects by their count values
Departure from previous western works on political power : Machiavelli’s book, The Prince, was considered a radical departure from previous western works on political power.
Why is it not surprising to find that in an oligopoly : Why is it not surprising to find that in an oligopoly which sells a basically undifferentiated product like chicken growth hormone all the firms change prices
Do any trees have euler traversals : Figure shows the original placement of the Bridges of K¨onigsberg. Could someone walk over each of the seven bridges and return to the starting point.
Likely reason corporation would issue yankee bond : Which of the following is not a likely reason a corporation would issue a Yankee bond?

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd