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()