Below is the code for the program I'm writing designed to read a
file and calculate the reading level and stuff. Right now I'm
having a problem compiling. It's complainin about missing "{"
and "}" around where I have throws IOException. Anyone have an idea?
import java.io.*;
public class Flesch throws IOException
{
private int mySentences, myWords, mySyllables;
private char check,hold;
private String myFile,myLevel;
private double myScore,wps,spw;
FileReader r;
public Flesch()
{
mySentences=0;
myWords=0;
mySyllables=0;
myLevel="";
check='?';
hold=check;
myScore=0.0;
}
public Flesch(String file)
{
myFile=file;
r=new FileReader(file);
}
public String getFilename()
{
return myFile;
}
public double getLegibilityIndex()
{
spw=((double)mySyllables)/((double)myWords);
wps=((double)myWords)/((double)mySentences);
wps=wps*1.015;
spw=spw*84.6;
myScore=wps+spw;
myScore=206.835-myScore;
return myScore;
}
public String getEducationalLevel()
{
if(myScore>=91)
myLevel="5th Grade";
else if(myScore>=81)
myLevel="6th Grade";
else if(myScore>=71)
myLevel="7th Grade";
else if(myScore>=61)
myLevel="8th and 9th Grade";
else if(myScore>=51)
myLevel="10th to 12th Grade";
else if(myScore>=31)
myLevel="College Student";
else myLevel="College Graduate";
return myLevel;
}
public int getNumSentences()
{
while(r.read()!=-1)
{
check=(char)r.read();
if(check=='?'||check=='!'||check=='.')
mySentences++;
}
return mySentences;
}
public int getNumWords()
{
check=(char)r.read();
while(r.read()!=-1)
{
hold=check;
if(check==' '&&hold!=' ')
myWords++;
check=(char)r.read();
}
return myWords;
}
public boolean isVowel(char c)
{
if
(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'||c=='y'||c=='A'||c=='E'||c=='
I'||c=='O'||c=='U'||c=='Y')
return true;
return false;
}
public int getNumSyllables()
{
check='?';
hold='?';
while(r.read()!=-1)
{
check=(char)r.read();
if(isVowel(check)&& (!isVowel(hold)))
mySyllables++;
if(check==' '&&hold=='e')
mySyllables--;
hold=check;
}
return mySyllables;
}
}