Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The grade level is calculated with the following formula: total words total sent

ID: 3709987 • Letter: T

Question

The grade level is calculated with the following formula: total words total sentences +11.8 total syllables total words 0.39 15.59 Problem. Using this formula and your knowledge of how to input and output text files, write a program that will take in a text file and return the number of words in the text, the number of sentences in the text, the number of syllables in the text, and the Flesch-Kincaid Grade Level. Please use the three files provided (gettysburg.txt, declaration.txt, and green_eggs_and ham.txt. Assumption: the number of syllables for each word is the number of letters in the word divided by three. Use integer math to calculate the number of syllables for each word Constraint: This program requires two classes: GradeLevel and GradeLevelTest. GradeLevel will be the repository for all methods, other than main, used in the grade level calculations. Examples: processLine, wordCount, sentenceCount, numberSyllables, ,,,. GradeLevelTest will have the main method. Additional Requirement: Use at least one Exception Handling Mechanism.

Explanation / Answer

import java.util.*;
import java.io.*;

class GradeLevel
{
public void countAll()
{
try
{
String fName,input;
int lineCount=0,vowCount=0,puctCount=0,charCount=0,wordCount=0,SentCount=0;
int i,j;
char ch;
char vowArray[]={'A','a','E','e','I','i','O','o','U','u'};
char punctArray[]={'.','!',',','?',':',';'};
char spacesArray[]={' ',' ',' '};
//reading fileusing file name
Scanner in=new Scanner(System.in);
System.out.print("Enter input file name: ");
fName=in.next();
//output file initialization
PrintStream ps=new PrintStream(new File("output.txt"));
Scanner sc=new Scanner(new FileReader(fName));
  
//condition to chech file empty
if(!(sc.hasNext()))
{
System.out.println(fName+"File is empty.");
System.exit(1);
}

while(sc.hasNextLine())
{
input=sc.nextLine();
wordCount++;
for(i=0;i<input.length();i++)
{
ch=input.charAt(i);
charCount++;
for(j=0;j<spacesArray.length;j++)
{
if(ch==spacesArray[j])
wordCount++;
}
for( j=0;j<punctArray.length;j++)
if(ch==punctArray[j])
{
puctCount++;
if(j<3)
SentCount++;
}   
for( j=0;j<vowArray.length;j++)
if(ch==vowArray[j])
vowCount++;
}   
lineCount++;   
}

double R1=(0.39*(wordCount/SentCount) );
double R2=(11.8*(vowCount/wordCount));
double result=((R1+R2)-15.59);
//to print output on console
System.out.println("word count is: "+wordCount);
System.out.println("line count is: "+lineCount);
System.out.println("sentence count is: "+SentCount);
System.out.println("vowel count is: "+vowCount);
System.out.println("character count is: "+charCount);
System.out.println("punctuation count is: "+puctCount);
System.out.println("GradeLevel calculation final result is:"+result);
//to write output in output.txt file
ps.println("word count is: "+wordCount);
ps.println("line count is: "+lineCount);
ps.println("sentence count is: "+SentCount);
ps.println("vowel count is: "+vowCount);
ps.println("character count is: "+charCount);
ps.println("punctuation count is: "+puctCount);
ps.println("GradeLevel calculation final result is:"+result);
//close input output file
ps.close();
sc.close();
System.exit(0);
}
catch ( FileNotFoundException e)
{
System.out.println(" File not exist or incorrect name specified.");
System.exit(2);
}
}
}

public class GradeLevelTest
{
public static void main(String[] args)throws FileNotFoundException
{
GradeLevel gl=new GradeLevel();
gl.countAll();
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote