New to Java - last minute homework help!

I have been working on this assignment for 3 weeks and need to submit it by 12/21/06. I cannot compile the code, and I have a feeling it is a simple error in the order of my code, but I cannot seem to figure it out. Can anyone please look at my code and help me find my error?

//Filename: Lab10Rough.java

//Purpose: Print a formatted student grade report to a file named "Lab10.txt"

import java.text.*; //imports java text class

import java.io.*; //imports java io class

public class Lab10Rough

{

public static void main(String[] args) throws Exception

{

String stuName; //student name string

String stuNum; //student name string

String courseNamSec; //course name and section string

String numCoursesString; //String for number of courses taken

String gpaOutput; //formatted output string for grade point average

String letterGradeString; //final letter grade string

float gradePoints; //creates variable for number of gradepoints per letter grade

char letterGrade; //variable for letter grade

double numCourses; //variable for number of courses

double gpa; //variable for grade point average

double sumGradePoints; //variable for total number of grade points

double count; //variable for counter

FileWriter fw = new FileWriter("Lab10.txt"); //creates file "Lab10.txt"

BufferedWriter bw = new BufferedWriter(fw); //writes buffer to file

PrintWriter pw = new PrintWriter(bw); //prints to buffer

DecimalFormat num = new DecimalFormat("###.00"); //decimal format for named num

InputStreamReader isr = new InputStreamReader(System.in); //creates stream input reader isr

BufferedReader br = new BufferedReader(isr); //reads input stream to buffer

System.out.print("Enter the number of courses taken: "); //prompt user for number of courses

numCoursesString = br.readLine(); //reads number of courses string to buffer

numCourses = Double.parseDouble(numCoursesString); //converts string to usable number

System.out.print("Enter your name: "); //prompt user for name

stuName = br.readLine(); //reads name string to buffer

System.out.print("Enter your student number: "); //prompt user for student number

stuNum = br.readLine(); //reads student number to buffer

pw.println("Bucks County Community College Grade Report For"); //output heading

pw.println(stuName); //output subheading

pw.println(stuNum);//output sub-subheading

pw.println("Course \tGrade \tGradepoints"); //output column heading

for(count = 0; count < numCourses; count++) //counter controlled loop

{

//prompt user for course name and section

System.out.print("What is your course name and section? (ex. CISC115.59): ");

courseNamSec = br.readLine(); //reads course name and section string to buffer

//prompt user for letter grade

System.out.print("What is your letter grade for the course? (no + or -): ");

letterGradeString = br.readLine(); //reads letter grade string to buffer

letterGrade = letterGradeString.charAt(0); //converts string to usable character

switch(letterGrade) //assigns grade points based on letter grade

{

case 'A':

gradePoints = 4.00f; //grade points for an 'A' letter grade

break;

case 'B':

gradePoints = 3.00f; //grade points for a 'B' letter grade

break;

case 'C':

gradePoints = 2.00f; //grade points for a 'C' letter grade

break;

case 'D':

gradePoints = 1.00f; //grade points for a 'D' letter grade

break;

case 'F':

gradePoints = 0.00f; //grade points for an 'F' letter grade

break;

default:

gradePoints = 0.00f; //default grade points for invalid entry

System.out.println("Invalid letter entry"); //output for an invalid letter grade

break;

}

}

pw.println(courseNamSec + "\t" + letterGrade + "\t" + gradePoints); //output to file

sumGradePoints += gradePoints; //adds all grade points to get a total number of grade points

gpa = sumGradePoints / numCourses; //calculates grade point average

gpaOutput = num.format(gpa); //formats grade point average output

pw.println(gpaOutput); //writes grade point average output to file

pw.close(); //exit

}

}

[4429 byte] By [rjpilla55a] at [2007-11-26 13:10:50]
# 1
1) put code tags around your code2) why can't you compile the code ? If you don't have a compilier setup you're in trouble, if it's giving you errors post them.
Aknibbsa at 2007-7-7 17:25:36 > top of Java-index,Java Essentials,Java Programming...
# 2

There are paths though to

pw.println(courseNamSec + "\t" + letterGrade + "\t" + gradePoints); //output to file

sumGradePoints += gradePoints; //adds all grade points to get a total number of grade points

which allow three of your values not to have been initialised. You need to make sure they are always initialised.

Note - variables local to a method are not initialised by declaring them unless you explicitly do so.

P.S. That is the worst set of comments I have ever ever seen.

sabre150a at 2007-7-7 17:25:36 > top of Java-index,Java Essentials,Java Programming...
# 3

I found 3 bugs.

1) you can't compile because you try to use variable that may not be initialized

2) you are only printing the last set of course/grade info to the file

3) you need to sum your grade points in the loop, not after it

4) Bonus -- if a user enters an invalid grade, do you really want to give him 0 points, and use that to calc gpa? also, you should not force the user to use upper case grade when entering. convert to upper then get the first char.

Have fun, this should be enough for you to fix the problems, post back if you get stuck

~Tim

SomeoneElsea at 2007-7-7 17:25:36 > top of Java-index,Java Essentials,Java Programming...
# 4

Thanks to everyone, your replies should help me along the right path.

P.S. Sabre, this is a rough copy and the current comments were for my personal use, sorry if they were too rough to allow for forum assistance, I will take that into consideration for any future posts. Thanks again everyone!

rjpilla55a at 2007-7-7 17:25:36 > top of Java-index,Java Essentials,Java Programming...
# 5

> Thanks to everyone, your replies should help me along

> the right path.

Great.

>

> P.S. Sabre, this is a rough copy and the current

> comments were for my personal use,

But they provide absolutely no extra information. The just duplicate what the statements say.

> sorry if they were

> too rough to allow for forum assistance,

Those sort of comments just add clutter.

> I will take

> that into consideration for any future posts.

By all means use comments but make them add something that the reader won't get from the code.

> Thanks

> again everyone!

sabre150a at 2007-7-7 17:25:36 > top of Java-index,Java Essentials,Java Programming...
# 6
Thanks for the Dukes 'rjpilla55'. I hope you get a good grade.
sabre150a at 2007-7-7 17:25:36 > top of Java-index,Java Essentials,Java Programming...
# 7
Thanks for the Dukes, Glad I could help.~Tim
SomeoneElsea at 2007-7-7 17:25:36 > top of Java-index,Java Essentials,Java Programming...