Help Please.. Sorting an array with a class.

Hello

I'm having trouble sorting an array that uses a class. I have to sort it by GPA and I can't quite get it.

Here's my code:

package test2;

import java.io.*;

public Main()

{

}

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

{

BufferedReader input = new BufferedReader (new InputStreamReader(System.in));

//System.out.println("Enter File 1");

//String file1 = input.readLine();

String file1 = "c:/studentfile1.dat";

//System.out.println("Enter File 2");

//String file2 = input.readLine();

String file2 = "c:/studentfile2.dat";

FileWriter OutputFile = new FileWriter ("c:/studentreport.csv");

PrintWriter OutFile = new PrintWriter (OutputFile);

// Create and Size Array

FileReader InputFile1 = new FileReader (file1);

BufferedReader InFile1 = new BufferedReader (InputFile1);

FileReader InputFile2 = new FileReader (file2);

BufferedReader InFile2 = new BufferedReader (InputFile2);

String arraycount1;

arraycount1 = InFile1.readLine();

String arraycount2;

arraycount2 = InFile2.readLine();

String buffer;

int File1Count = 0;

int File2Count = 0;

while (arraycount1 != null)

{

buffer = InFile1.readLine();

File1Count ++;

arraycount1 = InFile1.readLine();

}

while (arraycount2 != null)

{

buffer = InFile2.readLine();

buffer = InFile2.readLine();

File2Count ++;

arraycount2 = InFile2.readLine();

}

InFile1.close();

InFile2.close();

System.out.println (File1Count +" Students have been found.");

System.out.println ("And " +File2Count +" total entries have been located");

Student[] students = new Student[File2Count];

// End Create and Size Array

FileReader InputFile3 = new FileReader (file1);

BufferedReader InFile3 = new BufferedReader (InputFile3);

FileReader InputFile4 = new FileReader (file2);

BufferedReader InFile4 = new BufferedReader (InputFile4);

//Class

int StudentID;

String StudentName;

double GPA;

int HRS;

String GRADE;

//Class

String IDone;

String IDtwo;

String Name;

String gpa;

String hrs;

int idONE;

int idTWO;

IDone = InFile3.readLine();

idONE = Integer.parseInt(IDone);

Name = InFile3.readLine();

IDtwo = InFile4.readLine();

idTWO = Integer.parseInt(IDtwo);

for (int i = 0; i < File2Count; i++)

{

if (idONE == idTWO)

{

StudentID = idONE;

StudentName = Name;

hrs = InFile4.readLine();

HRS = Integer.parseInt(hrs);

gpa = InFile4.readLine();

GPA = Double.parseDouble(gpa);

GRADE = "A";

System.out.println ( StudentID + "," + StudentName + "," + GPA + "," + HRS + "," + GRADE );

students = new Student(StudentID, StudentName, HRS, GPA, GRADE);

}

IDtwo = InFile4.readLine();

if (IDtwo != null)

{

idTWO = Integer.parseInt(IDtwo);

if (idONE != idTWO)

{

IDone = InFile3.readLine();

idONE = Integer.parseInt(IDone);

Name = InFile3.readLine();

}

}

}

InFile3.close();

InFile4.close();

OutFile.close();

}

}

[3365 byte] By [bronze-starDukes] at [2007-11-26 12:13:59]
# 1

Sorry... we are told to use NetBeans and I forgot to add the class I used

package test2;

public class Student

{

public int StudentID;

public String StudentName;

public int HRS;

public double GPA;

public String GRADE;

public Student(int s, String n, int h, double g, String a)

{

StudentID = s;

StudentName = n;

HRS = h;

GPA = g;

GRADE = a;

}

}

bronzestar at 2007-7-7 14:15:57 > top of Java-index,Archived Forums,Socket Programming...
# 2
try to post your code inside code tags. (next time)tryArray.sort(yourArray);=)
bronzestar at 2007-7-7 14:15:57 > top of Java-index,Archived Forums,Socket Programming...
# 3
I'm sorry but I'm not sure how to add theArray.sort(yourArray);or where to add it... I think my instructor didn't do very well...Thanks
bronzestar at 2007-7-7 14:15:57 > top of Java-index,Archived Forums,Socket Programming...
# 4
here's an example from Java Developers Almanac. http://www.exampledepot.com/egs/java.util/coll_SortArray.html=)
bronzestar at 2007-7-7 14:15:57 > top of Java-index,Archived Forums,Socket Programming...
# 5
> I think my instructor didn't do very well...Ah yes! It's always the instructors fault and never the lazy student.
goldstar at 2007-7-7 14:15:57 > top of Java-index,Archived Forums,Socket Programming...
# 6
Very funny... that's why I know more about my teacher's company in mexico than sorting an array... It's also nice to know that my 60% on tests put me near top of my class.thanks
bronzestar at 2007-7-7 14:15:57 > top of Java-index,Archived Forums,Socket Programming...