Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

FileReader problem

  Asked By: Oscar    Date: Oct 19    Category: Java    Views: 597
  

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;
}
}

Share: 

 

4 Answers Found

 
Answer #1    Answered By: Kerry Wright     Answered On: Oct 19

Classes don't throw exceptions, methods do.

 
Answer #2    Answered By: Miriam Green     Answered On: Oct 19

i also think that where you put new FileReader(), do not capitalize
the f. it should be new fileReader()....if that part of your code
had a compiling  error.

 
Answer #3    Answered By: Alberta Miller     Answered On: Oct 19

FileReader is the correct class  name. Do not change the F to a lowercase.

 
Answer #4    Answered By: Debbie Reyes     Answered On: Oct 19

fixed it, i had to put throws  IO Exception next to all the methods
that used file stuff

 
Didn't find what you were looking for? Find more on FileReader problem Or get search suggestion and latest updates.




Tagged: