Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

Write a program that reads in a text file and then computes and prints a table of letter frequencies. For example, if the file is the text of "A Tale of Two Cities", found in the file atdata/tales.txt, the program will print:

 

Please enter the pathname or URL of the book file: data/tales.txt
Letter frequencies in data/tales.txt
a        47,065
b         8,142
c        13,223
d        27,484
e        72,878
f        13,152
g        12,121
h        38,355
i        39,779
j           622
k         4,633
l        21,516
m        14,924
n        41,308
o        45,115
p         9,452
q           655
r        35,950
s        36,771
t        52,393
u        16,217
v         5,065
w        13,835
x           666
y        11,849
z           213


I am confused as to how to represent my code in this nice table above.  Any hints? Here is my code so for:
package assignment3solutions;

import java.util.ArrayList;

import stdlib.In;
import stdlib.StdIn;
import stdlib.StdOut;

public class LetterFrequencies {
        
        public static void main(String[] args){
                
                StdOut.println("Please enter the pathname or URL of the book file: ");
                String textSource = StdIn.readLine();
                
                final In in = new In(textSource);
                if(!in.exists()){
                        StdOut.print("Unable to open file " + textSource);
                System.exit(1);
                }
                
                String[] bookOfWords = bookFile.split("\\s+");
                
                ArrayListwordFrequencies = new ArrayList();
                
                for(String word: bookOfWords){
                        wordFrequencies.add()

 

 

Java, Programming

  • Category:- Java
  • Reference No.:- M9458184

Have any Question?


Related Questions in Java

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 ...

Simple order processing systemquestion given the classes

Simple Order Processing System Question: Given the classes Ship (with getter and setter), Speedboat, and SpeedboatTest. Answer the following questions: Refine the whole application (all classes) and create Abstract class ...

In relation to javaa what is constructor the purpose of

(In relation to Java) A. What is constructor? the purpose of default constructor? B. How do you get a copy of the object but not the reference of the object? C. What are static variables and instance variables? D. Compar ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Assessment instructionsin this assessment you will complete

Assessment Instructions In this assessment, you will complete the programming of two Java class methods in a console application that registers students for courses in a term of study. The application is written using th ...

Solving 2nd degree equationsbull write the following java

Solving 2nd degree equations • Write the following Java methods • boolean real-sols(double a, double b, double c): it returns true if the 2nd degree equation ax2 + bx + c has real solutions • double solution1(double a, d ...

Part a specification - robot simulationpart a

PART A Specification - Robot Simulation PART A Requirements To complete this assignment you will use the supplied eclipse project Robot P1/. It is already set up to execute a simple arm movement loop which you will build ...

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?

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

  • 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