I need help with writing this java program. It consists of refactoring the imple
ID: 3847672 • Letter: I
Question
I need help with writing this java program. It consists of refactoring the implementation of reading levels (Gunning Fog index, Flesch Formula, and Reading Ease Score). We are supposed to use the javadoc documentation format to list the names of the methods along with documentation describing it. We are required to use the main(), getWords(), getSentences(), getBigWords(), getSyllables(), GunningFog(), FleschREScore(), FleschGL(), and displayResults(). We also have to have a single Scanner for the entire program and can only have a global Scanner and no other variables declared outside of methods. Thanks!
Explanation / Answer
import java.util.Scanner;
public class MyReadabilityApp {
public static Scanner sc = new Scanner(System.in);
Integer sentences;
Integer complex;
Integer words;
Integer syllables;
Integer characters;
public Integer getCharacters() {
return characters;
}
public Integer getComplex() {
return complex;
}
public Integer getSentences() {
return sentences;
}
public Integer getSyllables() {
return syllables;
}
public Integer getWords() {
return words;
}
public MyReadabilityApp() {
System.out.print("Enter string : ");
String _txt = sc.nextLine();
this.sentences = getTotalSentences(_txt);
this.complex = getTotalComplexWords(_txt);
this.words = getNumberOfWords(_txt);
this.syllables = getTotalSyllables(_txt);
this.characters = getTotalCharacters(_txt);
}
private static boolean isSyllableComplex(String w) {
if(w.contains("a") || w.contains("e") || w.contains("i") || w.contains("o") || w.contains("o")){
return true;
}
return false;
}
private static Integer getTotalCharacters(String _txt) {
String[] word = _txt.split(" ");
Integer characters = 0;
for (String wrd : word) {
characters += wrd.length();
}
return characters;
}
//get complex words
private static Integer getTotalComplexWords(String _txt) {
String[] words = _txt.split(" ");
int complex = 0;
for (String ww : words) {
if (isSyllableComplex(ww)) complex++;
}
return complex;
}
private static Integer getNumberOfWords(String _txt) {
String[] word = _txt.split(" ");
int words = 0;
for (String ww : word) {
if (ww.length()>0) words ++;
}
return words;
}
private static Integer getTotalSyllables(String _txt) {
String[] word = _txt.split(" ");
int syllables = 0;
for (String wrd : word) {
if (wrd.length()>0) {
syllables ++;
}
}
return syllables;
}
private static Integer getTotalSentences(String _txt) {
int l = _txt.length();
if (l>0) return l;
else if (_txt.length()>0) return 1;
else return 0;
}
public Double calculateSMOGIndex() {
double score = Math.sqrt( complex * (30.0 / sentences) ) +3;
return score;
}
public Double get_smog() {
double score = 1.043 * Math.sqrt( complex * (30.0 / sentences) ) +3.1291;
return score;
}
public Double get_FleschReadingEase() {
double score = 206.835 - 1.015*words/sentences - 84.6*syllables/words;
return score;
}
public Double get_FleschKincaidGradeLevel() {
double score = 0.39 * words/sentences + 11.8 * syllables/words - 15.59;
return score;
}
public Double getARI() {
double score = 4.71 * characters/words + 0.5 * words/sentences - 21.43;
return score;
}
public double getGunningFog() {
double score = 0.4 * (words/sentences + 100 * complex/words);
return score;
}
public Double getColemanLiau() {
double score = (5.89 * characters/words) - (30 * sentences/words) - 15.8;
return score;
}
public static void main(String[] args) {
MyReadabilityApp r = new MyReadabilityApp();
System.out.println("smog_index -> " + r.calculateSMOGIndex() );
System.out.println("smog -> " + r.get_smog() );
System.out.println("Flesch_Reading Ease -> " + r.get_FleschReadingEase() );
System.out.println("Flesch-Kincaid Grade Level -> " + r.get_FleschKincaidGradeLevel() );
System.out.println("Index -> " + r.getARI() );
System.out.println("Gunning-Fog Index -> " + r.getGunningFog() );
System.out.println("Coleman-Liau Index -> " + r.getColemanLiau() );
}
}