Any java boffins about that can check this for me. It keeps returning Grade as a null instead of the Character its ment to be set at. I need a fresh pair of eyes as I must be looking to hard at it now. Any help would be much appreciated.
/****************************************************************************
* Program Name : Student Grant *
* Author : David Gillespie *
* Date : 18/12/06 *
* The program will read in 10 student names and marks from a text document*
* The system will ask the user to set grades (i.e A > 80) the program will*
* convert the marks into the grades specified by the user and Save it in *
* a .txt file. *
****************************************************************************/
//Calling function for the program to use to keep size down
import java.io.*;
import java.util.*;
public class studentGrant
{//Start of class Student Grant
//set Constant for number of students
final static int No_of_Students = 10;
//allow input from keyboard
static BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
//********************Create Records*************************************
static class Student_Grades{
String Name;
int Mark;
Character Grade;
}//End of record Declaration
//******************** Read Marks File *********************************
static boolean readMarksFile (Student_Grades[] Grades)
{//read the information from file. If no file exists then trap it in an error
//variable declaration section
boolean FileFound = false;
try
{//Specify and access chosen file
//variable declaration section
StringTokenizer Tokenizer;
String Dir_Name ="C:\\Java\\text\\";
String File_Name="Marks.txt";
File Input = new File(Dir_Name, File_Name);
String LineInFile, Firstname, Surname;
BufferedReader tempFile = new BufferedReader(new FileReader(Input));
for(int loop = 0; loop < No_of_Students; loop++)
{//Sets Values from Marks Files
LineInFile = tempFile.readLine();
Tokenizer = new StringTokenizer(LineInFile);
Firstname = Tokenizer.nextToken();
Surname =Tokenizer.nextToken();
Grades[loop].Name = (Firstname+" "+Surname);
Grades[loop].Mark = Integer.parseInt(Tokenizer.nextToken());
}//end for
//Tells the calling function the file was found
FileFound = true;
//Closes the Marks file after use
tempFile.close();
}//end try
catch(FileNotFoundException error)
{//Insert Comment Here
System.err.println(error);
}//end no file catch
catch(IOException error)
{//Insert Comment Here
System.err.println(error);
}//end ioexception catch
finally
{//Insert Comment Here
return (FileFound);
}//end finally
}
Fear wrote:Bah, Zip up your project and sling it over. I have enough debuggers here, I must have something that can debug it. I need the txt files also.
//******************Allocate Grade***************************************
static Character allocateGrade(int Mark, int[] gradeLevels)
{
//declare Variables
Character grade;
if (Mark >= gradeLevels[0])
grade = new Character('A');
else if (Mark >= gradeLevels[1])
grade = new Character('B');
else if (Mark >= gradeLevels[2])
grade = new Character('C');
else if (Mark >= gradeLevels[3])
grade = new Character('D');
else
grade = new Character('E');
return grade;
}
Also noticed: tempMark in updateStudentMark tempString in writeGradesToFile
are unused.
Hope that helps.
Cheers, Doesn't appear to work that way either. Thanks very much for looking at it though. I'll just do all the paper work for it and say it doesn't work then do it the Way I would have done it as a fix that should sort stuff out. (my way means new class array for Grades instead of adding it to the student_grades class.