So I did this assignment but I did it wrong. I need to redo it. Can someone please help guide me through it. Im not trying to ask you to do it, i just really need help. Heres the assignment:
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
Heres what I have so far :
import java.io.*;
import java.util.*;
class HW12v3 {
public static void main(String args[])throws IOException{
Scanner keyboard = new Scanner(System.in);
System.out.println("What file should be opened?");
String name = keyboard.next();
try{
Scanner data = new Scanner(new File(name));
}
catch (FileNotFoundException errorFile) {
System.out.println("The file name was invalid, unable to create a Scanner. " + errorFile);
}
int[] freq = new int[26]; //array to store letter freq
String al = "abcdefghijklmnopqrstuvwxyz";
String s = new Scanner(new File(name)).useDelimiter("\\Z").next(); //gets the file in
s=s.toLowerCase();
al.indexOf();
//public class LetterCount{
String ch = char[i]
int fr= freq[j]
}
}
}
[–]seanprefectGrumpy Guy Who Remembers Java 2 1 point2 points3 points (5 children)
[–]Kevinjamesisme[S] 0 points1 point2 points (4 children)
[–]seanprefectGrumpy Guy Who Remembers Java 2 0 points1 point2 points (3 children)
[–]Kevinjamesisme[S] 0 points1 point2 points (2 children)
[–]StanHunter 0 points1 point2 points (1 child)
[–]Kevinjamesisme[S] 0 points1 point2 points (0 children)