Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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

Java, Programming

  • Category:- Java
  • Reference No.:- M92394616
  • Price:- $20

Priced at Now at $20, Verified Solution

Have any Question?


Related Questions in Java

Can someone help me please with those question1what is the

Can someone help me please with those question 1:what is the best data type for student id datatime,currency,number,decimal 2:which relationshipis preferable? one to one,one to many,many to many 3:if you add table A's pr ...

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

Answer the following question whats the difference public

Answer the following Question : What's the difference public inheritance and private inheritance? What can derived classes inherit from base classes? What cannot be inherited from base classes?

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Fundamentals of operating systems and java

Fundamentals of Operating Systems and Java Programming Purpose of the assessment (with ULO Mapping) This assignment assesses the following Unit Learning Outcomes; students should be able to demonstrate their achievements ...

Can someone please help me with the following java

can someone please help me with the following java question The input is an N by N matrix of nonnegative integers. Each individual row is a decreasing sequence from left to right. Each individual column is a decreasing s ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

Operating systems assignment -problem 1 sharing the bridgea

Operating Systems Assignment - Problem 1: Sharing the Bridge A new single lane bridge is constructed to connect the North Island of New Zealand to the South Island of New Zealand. Farmers from each island use the bridge ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As