Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

need help to get this to compile so i can work on the next part  RSS feed

 
Jared Upton
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.util.*; // for the Scanner class
import java.io.*; // for the File class


public class gradecalc {

double[] grades = new double[7];

public void readgrades() {
try {
File grades = new File("grades.txt");
FileReader fr = new FileReader(grades);
BufferedReader br = new BufferedReader(fr);
} catch(Exception ex) {
ex.printStackTrace();
}
}






public void parsefile() {

double ratscore = 0.0;
double programscore = 0.0;
double examscore = 0.0;
double teamratscore = 0.0;
double teamXMLscore = 0.0;
double teamexamscore = 0.0;
double peerevalscore = 0.0;
double s = 0.0;

for (int i = 0; i < grades.length; i++) {
readLine(s);
double value = Double.parseDouble(s);
grades[i] = readLine(s);

}
}

public static void main() {
readgrades();
parsefile();



} //Main
}// cla
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One thing I see is that you are calling a method readLine that you haven't defined.

A bigger problem is in the logic of your method readFile. You are making a connection to the file and creating a BufferedReader. But you aren't using it.

Did you intend to use the BufferedReader where you called readLine()?
 
Jared Upton
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeh I plan on using the readLine to call the information in the BufferedReader.
How should I define it?
[ April 14, 2006: Message edited by: Jared Upton ]
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay... You need to back up and take this one step at a time.

First, your main method is not an entry point. You need it to take a String array as an argument.

Second, main is a static method, so you can't directly call instance (non-static) methods from it. In particular, you can't just call readgrades() or parsefile(). You should probably create an instance of gradecalc in main so you can call the methods on that.

Next, you have a method that creates a BufferedReader. But that's all it does. There is no reference to a BufferedReader outside of that method, so the reader can't be used outside of that method. You might try declaring an instance variable to reference this.

Once you have a reference to the reader, you can use it to call readLine(). However, readLine() takes no arguments and it returns a String (not a double). Also, readLine() could throw an IOException, so you will probably want to put this call in a try/catch block.

Finally, parseDouble takes a String argument (not a double).
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use Code Tags to keep your indentation intact.
 
Jared Upton
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay i got the thing to compile but it is not printing out the
System.out.println("Rat:" + ratscore);





import java.util.*; // for the Scanner class
import java.io.*; // for the File class


public class calc {

public static void main (String[] args)
{
calc mygrade = new calc();
mygrade.readgrades();
}


public void readgrades() {
double[] scores = new double[7];
double ratscore = 0.0;
double programscore = 0.0;
double examscore = 0.0;
double teamratscore = 0.0;
double teamXMLscore = 0.0;
double teamexamscore = 0.0;
double peerevalscore = 0.0;
double linedouble = 0.0;

try {
File grades = new File("grades.txt");
FileReader fr = new FileReader(grades);
BufferedReader br = new BufferedReader(fr);
String line = br.readLine();
for (int i = 0; i < 7; i++) {
scores[i] = Double.parseDouble(line);
line = br.readLine();
}
br.close();
} catch(Exception ex) {
ex.printStackTrace();


ratscore = scores[0];
programscore = scores[1];
examscore = scores[2];
teamratscore = scores[3];
teamXMLscore = scores[4];
teamexamscore = scores[5];
peerevalscore = scores[6];
System.out.println("Rat:" + ratscore);

}



}
}
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason its not printing anything is you have all the assignment/printing logic in the catch block. The catch block will only execute if there is an exception thrown, move this stuff outside the catch block and see what happens.

BTW please use Code Tags when posting code so that the formatting will be preserved and you will be more likely to get timely responses.
[ April 14, 2006: Message edited by: Garrett Rowe ]
 
Jared Upton
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks makes me feel like an idiot
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!