Question: JAVA NEED HELP FIXING CODE In this you are to implement a simplified version of the Flesch reading-ease test. Create a program called FleschReadingEase that

JAVA NEED HELP FIXING CODE

In this you are to implement a simplified version of the Flesch reading-ease test. Create a program called FleschReadingEase that meets the following requirements

1. Takes one argument from the command line. The name of the text file to read

a. If an invalid number of arguments is provided print

Usage: java FleschReadingEase filename

b. If the file doesn't exist print

FILE NOT FOUND

2. Implements the algorithm described below and prints the computed score

3. To help you develop the code you will be required to implement the following methods (all public and static):

a. getTokensFromFile

i. Input parameter: String

Filename to be read

ii. returns: String[]

Tokens of text in file

iii. Note: you need to implement error handling. Have the method throw FileNotFound Exception.

Your main method will have a try/catch block to handle any exception thrown by this method. See the class notes on using a try/catch block.

b. removeNonAlphabetCharacters

i. Input parameter: String

The original string possibly containing alphabet and non-alphabetic characters

ii. returns: String

A new string with all non-alphabetic characters removed

Hello! should return Hello

!@#$!goodbye<>: should return goodbye

You may find the Character.isLetter method helpful

c. getSentenceCount

i. Input parameter: String[]

Word tokens

ii. returns: int

Count of sentences using word counting algorithm listed below

d. getSyllableCount

i. Input parameter: String

A word

ii. returns: int

Count of syllables in word using the word counting algorithm listed below

e. getFleschScore

i. Input parameter: String[]

Tokenized input text

ii. returns: int

Calculated Flesch score using algorithm listed below

Algorithm Details

Count all tokens in the file. A token is any sequence of characters delimited by white space, whether or not it is an actual English word. There are multiple ways to do this. However, to make grading consistent you are to use a Scanner to generate tokens (which we assume to be words) using white space as the delimiter.

Count all syllables in each token. Use the following rules:

Vowels are: aeiouyAEIOUY

Each group of two vowels counts as one syllable (for example, the "ea" in "real" is one syllable.

Following our rules, the word you has two(2) syllables. The grouping of yo and the u

Each individual vowel that is not adjacent counts as one syllable ( for example, the "e .. a" in "regal" counts as two syllables).

However, an "e" or "E" at the end of a word doesn't count as a syllable.

Note: you will need to remove punctuation before counting syllables

Hint: use the removeNonAlphabetCharacters method

Also, each token has at least one syllable, even if the previous rules produce a count of 0.

Note: The above rules may not work in all cases and may produce incorrect syllable counts. There is no simple syllable counting method that works in all cases. These syllable rules apply to this assignment only.

Count all sentences. A sentence is ended by a period, colon, semicolon, question mark, or exclamation mark .:;?!. Assume the number of times these characters appear is equivalent to the number of sentences. ONLY count if the last character in the token is one of the punctuation marks.

The score is computed by the following formula rounded to the nearest integer.

Scores can be interpreted as shown in the table below.

Score

School level (US)

Notes

100 90

5th grade

Very easy to read. Easily understood by an average 11-year-old student.

90 80

6th grade

Easy to read. Conversational English for consumers.

80 70

7th grade

Fairly easy to read.

70 60

8th & 9th grade

Plain English. Easily understood by 13- to 15-year-old students.

60 50

10th to 12th grade

Fairly difficult to read.

50 30

College

Difficult to read.

30 10

College graduate

Very difficult to read. Best understood by university graduates.

10 0

Professional

Extremely difficult to read. Best understood by university graduates.

TESTED CODE:

import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class FleschReadingEase { public static void main(String[] args) { if (args.length != 1) { System.out.println("Usage: java FleschReadingEase filename"); return; } String filename = args[0]; try { String[] tokens = getTokensFromFile(filename); int sentenceCount = getSentenceCount(tokens); int syllableCount = 0; for (String token : tokens) { String word = removeNonAlphabetCharacters(token); int wordSyllables = getSyllableCount(word); syllableCount += wordSyllables > 0 ? wordSyllables : 1; } int fleschScore = getFleschScore(tokens, sentenceCount, syllableCount); System.out.println("Flesch reading ease score: " + fleschScore); } catch (FileNotFoundException e) { System.out.println("FILE NOT FOUND"); } } public static String[] getTokensFromFile(String filename) throws FileNotFoundException { File file = new File(filename); Scanner scanner = new Scanner(file); String[] tokens = scanner.useDelimiter("\\Z").next().split("\\s+"); scanner.close(); return tokens; } public static String removeNonAlphabetCharacters(String str) { return str.replaceAll("[^a-zA-Z]", ""); } public static int getSentenceCount(String[] tokens) { int sentenceCount = 0; for (String token : tokens) { char lastChar = token.charAt(token.length() - 1); if (lastChar == '.' || lastChar == ':' || lastChar == ';' || lastChar == '?' || lastChar == '!') { sentenceCount++; } } return sentenceCount; } public static int getSyllableCount(String word) { word = removeNonAlphabetCharacters(word.toLowerCase()); int syllableCount = 0; boolean lastWasVowel = false; for (int i = 0; i < word.length(); i++) { char c = word.charAt(i); boolean isVowel = "aeiouy".indexOf(c) != -1; if (isVowel && !lastWasVowel) { syllableCount++; } lastWasVowel = isVowel; } if (word.endsWith("e")) { syllableCount--; } syllableCount = syllableCount == 0 ? 1 : syllableCount; return syllableCount; } public static int getFleschScore(String[] tokens, int sentenceCount, int syllableCount) { double score = 206.835 - 1.015 * ((double)tokens.length / (double)sentenceCount) - 84.6 * ((double)syllableCount / (double)tokens.length); return (int)Math.round(score); } }

RESULTED ERROR:

Starting a Gradle Daemon (subsequent builds will be faster) > Task :clean > Task :compileJava > Task :processResources NO-SOURCE > Task :classes > Task :jar > Task :assemble > Task :compileTestJava FAILED /autograder/source/0P/src/test/FleschReadingEaseTest.java:317: error: method getFleschScore in class FleschReadingEase cannot be applied to given types; int actual = FleschReadingEase.getFleschScore(text); ^ required: String[],int,int found: String[] reason: actual and formal argument lists differ in length /autograder/source/0P/src/test/FleschReadingEaseTest.java:331: error: method getFleschScore in class FleschReadingEase cannot be applied to given types; int actual = FleschReadingEase.getFleschScore(text); ^ required: String[],int,int found: String[] reason: actual and formal argument lists differ in length /autograder/source/0P/src/test/FleschReadingEaseTest.java:345: error: method getFleschScore in class FleschReadingEase cannot be applied to given types; int actual = FleschReadingEase.getFleschScore(text); ^ required: String[],int,int found: String[] reason: actual and formal argument lists differ in length /autograder/source/0P/src/test/FleschReadingEaseTest.java:359: error: method getFleschScore in class FleschReadingEase cannot be applied to given types; int actual = FleschReadingEase.getFleschScore(text); ^ required: String[],int,int found: String[] reason: actual and formal argument lists differ in length 4 errors FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':compileTestJava'. > Compilation failed; see the compiler error output for details. * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. * Get more help at https://help.gradle.org BUILD FAILED in 12s 4 actionable tasks: 4 executed

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!