What I am trying to do is to sort my array so I can eventually output it to a print file, but I can't get it to sort. I can't find the error in my code, but I've been trying different methods to sort a string for about 2 hours. I can't use a predefined method for sorting (such as .sort from the array class), but I can't figure out why I keep getting this error. I know it's because I'm pointing somewhere I shouldn't, but I can't figure out why it's pointing there. I would be greatful for any help.
/*
Author:
Date:
Assignment:
*/
import java.io.*;
import java.lang.String;
public class Ajm01soccer
{
public static void main (String args[]) throws IOException
{
FileReader indisk = new FileReader("girls40.txt");
BufferedReader diskin = new BufferedReader(indisk);
FileWriter outdisk = new FileWriter("Ajm01soccer.txt");
PrintWriter diskprint = new PrintWriter(outdisk);
String girl1 = "";
String girl2 = "";
String girl3 = "";
String girl4 = "";
int radnum = 0;
int slot = 0;
String date = SoccerDateUtility.getTimeStamp();
String team1[] = new String [20];
String team2[] = new String [20];
String team3[] = new String [20];
String team4[] = new String [20];
diskprint.println("00000000011111111112222222222333333333344444444");
diskprint.println("12345678901234567890123456789012345678901234567");
diskprint.println("===============================================");
diskprint.println("Proj 1 Anthony Michael " + date);
diskprint.println("===============================================");
diskprint.println(" Lake Wobegon Girl's Soccer League ");
diskprint.println("");
diskprint.println("No. Team 1 Team 2 Team 3 Team 4 ");
diskprint.println("--- ---------- ---------- ---------- ----------");
do
{
girl1 = diskin.readLine();
girl2 = diskin.readLine();
girl3 = diskin.readLine();
girl4 = diskin.readLine();
radnum = 1 + (int)(Math.random() * 4);
if(radnum == 1)
{
team1[slot] = girl1;
team2[slot] = girl2;
team3[slot] = girl3;
team4[slot] = girl4;
}
if(radnum == 2)
{
team1[slot] = girl4;
team2[slot] = girl1;
team3[slot] = girl2;
team4[slot] = girl3;
}
if(radnum == 3)
{
team1[slot] = girl3;
team2[slot] = girl4;
team3[slot] = girl1;
team4[slot] = girl2;
}
if(radnum == 4)
{
team1[slot] = girl2;
team2[slot] = girl3;
team3[slot] = girl4;
team4[slot] = girl1;
}
slot++;
}while (diskin.ready() != false);
team1 = sortArray(team1);
outdisk.close();
}
public static String[] sortArray (String[] oldArray)
{
for (int i = 1; i < oldArray.length; i++)
{
int s = i-1;
for (int j = i; j < oldArray.length; j++)
{
if(oldArray[j].compareTo(oldArray[s]) < 0)
{
s = j;
}
}
String temp = oldArray[i-1];
oldArray[i-1] = oldArray[s];
oldArray[s] = temp;
}
return oldArray;
}
}
This post has been edited by aj_lavaca: 07 February 2012 - 12:53 AM

New Topic/Question
Reply



MultiQuote




|