i need to write a class program and a client program(2 programs)....The class pr
ID: 3535746 • Letter: I
Question
i need to write a class program and a client program(2 programs)....The class program will read my .txt file that has all different kinds of characters, numbers, letters and then will count only the alphabet but will count each one. So if A occurs 4 times then it will print A = 4 times, and will do that for each alphabet. I only need to count each occurence of each letter of the alphabet, not the numbers or characters so I will have the count for a, b, c, d, e,.....z. Then at the end will tell me which letter was used the most AND which letter was used the least. Then on the client program, it will call my methods from the class program.
Explanation / Answer
public class ReadFile {
void getStudentList(String fileName) {
char[] temp = new char[200]; //Array to store value
int alph[]=new int[26];
try {
File file = new File(fileName); //new file type is created
FileReader fileReader = new FileReader(file);
fileReader.read(temp); //file is read into array
for (char c : temp) {
if (((int)c) >=((int)'a') &&((int)c) <=((int)'z') && ((int)c) >=((int)'A') &&((int)c) <=((int)'Z')) {
int i = (int)c;
if(i<=90)
{i=i-65;}
else {i=i-97;}
alph[1]=alph[1]+1;
}
}
}
fileReader.close(); //After iteration file reader is closed
} catch (IOException e) {
System.out.println("Error in reading file due to " + e);
} catch (Exception e) {
System.out.println("Error");
}
} }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.