Error problem

My problem is as follows. My program reads a file of a list of student and their grades and prints out their score and and grade and then gives a total of the number of letter grades. My problem is that my toString method is returning a hexidecimal form of the String. Any suggestions would be helpful. Here is the code.

import java.io.*;

import java.util.ArrayList;

import java.util.StringTokenizer;

public class StudentClient

{

// StringTokenizer variables

private static FileInputStream inFile;

private static InputStreamReader inReader;

private static BufferedReader reader;

private static StringTokenizer token;

// Input string declaration

private static String inputLine;

// Necessary computation and presentation variables

private static int count = 0; // Counts the number of students

private static String output,temp,temp2,temp3;

private static char compare;

private static int asum, bsum, csum, dsum, fsum;

private static double average, percenta, percentb, percentc, percentd, percentf;

private static double avsum;

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

{initFile();

inputAnalyze();

inFile.close();

}

// Prepare file for input

public static void initFile() throws IOException

{

inFile = new FileInputStream ("C:\\Documents and Settings\\Bill\\Desktop\\QuizTF.txt"); // Insert correct file location

inReader = new InputStreamReader(inFile);

reader = new BufferedReader(inReader);

}

// Take data from file, analyze word and suffix structures, and compile plurals and suffix additions

public static void inputAnalyze() throws IOException

{

// Start first constructor and instantiate student object

Student key = new Student();

// Setup ArrayList

ArrayList students = new ArrayList();

// Read data line and pass it into created student

inputLine = reader.readLine();

key.setCorrectAns(inputLine);

// Read student scores data lines

inputLine = reader.readLine();

while (inputLine != null){

count++;

// Place string in an ArrayList

students.add(new Student(inputLine));

// Read next line for while loop

inputLine = reader.readLine();

}

// Calculate average and percentages

for (int i=0;i<count;i++){

Object Test = students.get(i);

output = ((Student)Test).toString();

// Testing only

System.out.println(output);

token = new StringTokenizer(temp);

temp2 = token.nextToken();

avsum += Double.parseDouble(token.nextToken());

temp3 = token.nextToken();

compare = temp3.charAt(0);

if (compare == 'A')

asum++;

if (compare == 'B')

bsum++;

if (compare == 'C')

csum++;

if (compare == 'D')

dsum++;

if (compare == 'F')

fsum++;

average = avsum/count;

percenta = asum/count;

percentb = bsum/count;

percentc = csum/count;

percentd = dsum/count;

percentf = fsum/count;

}

// Output results

System.out.println("The student results are as follows: " + '\n');

for(int i=0; i><count; i++){

System.out.println(students.get(i));

}

System.out.println('\n' + count + " students took the test.");

System.out.println("The class average is: " + average + "%");

System.out.println(percenta + "% of students received an A");

System.out.println(percentb + "% of students received a B");

System.out.println(percentc + "% of students received a C");

System.out.println(percentd + "% of students received a D");

System.out.println(percentf + "% of students received an F");

}

}>

[3861 byte] By [bill6266a] at [2007-10-2 13:37:57]
«« postfix.?
»» help!!!
# 1

> the number of letter grades. My problem is that my

> toString method is returning a hexidecimal form of

> the String.

Fundamentally the problem is that toString method is NOT yours. It's the default one which is showing you something but not what you want. Override the toString method in your Student class and have it do what you want and all will be well.

bill6266a at 2007-7-13 11:28:25 > top of Java-index,Java Essentials,Java Programming...
# 2

What looks to be your problem is that the method toString() defined in Object is not returning quite for what you are looking. Try creating a method in Student named toString() to return whatever property or properties you want.

Note: I do not fully understand your conversion of a Test type object to a Student since you did not post the code for those objects. This could also be part of the problem.

KillerOfThema at 2007-7-13 11:28:25 > top of Java-index,Java Essentials,Java Programming...
# 3
thanks I will try that.
bill6266a at 2007-7-13 11:28:25 > top of Java-index,Java Essentials,Java Programming...
# 4
yes, that should work
WhiteSox2244a at 2007-7-13 11:28:25 > top of Java-index,Java Essentials,Java Programming...