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: 3710421 • 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

Hi Student,

Please find the code below :

import java.io.*;

import java.util.Scanner;

class GradeLevel

{

private File file;

private int countWord = 0;

private int sentenceCount = 0;

private int syllablesCount =0;

private double gradeLevel = 0;

  

public GradeLevel(String fileName){

file = new File(fileName);

}

  

public void calculate() throws IOException{

FileInputStream fileStream = new FileInputStream(file);

InputStreamReader input = new InputStreamReader(fileStream);

BufferedReader reader = new BufferedReader(input);

String line;

  

while((line = reader.readLine()) != null)

{

if(!(line.equals("")))

{

// \s+ is the space delimiter in java

String[] wordList = line.split("\s+");

for(int i=0;i<wordList.length;i++){

syllablesCount = syllablesCount + (wordList[i].length()/3); // calculate syllable

}

  

countWord += wordList.length;

// [!?.:]+ is the sentence delimiter in java

String[] sentenceList = line.split("[!?.:]+");

sentenceCount += sentenceList.length;

}

}

// as per given formula

gradeLevel =( 0.39 * (countWord/sentenceCount) )+ (11.8*(syllablesCount/countWord)) - 15.59;

  

System.out.println("Total word count = " + countWord);

System.out.println("Total number of sentences = " + sentenceCount);

System.out.println("Total Syllables = "+syllablesCount);

System.out.println("Grade Level = "+gradeLevel);

}

}

public class GradeLevelTest{

  

public static void main(String[] args) throws IOException

{

Scanner s = new Scanner(System.in);

System.out.println("Enter the file name");

  

String filename = s.next(); // take user input ie location to a file e.g C:\Users\Mayank\Desktop\1.txt

GradeLevel gl = new GradeLevel(filename);

gl.calculate(); // method call

}

}

Happy Learning :)

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