1. Use a different type of array, maybe a short array. Not sure if that would make a difference.
2. Read the first letter of the slots of the array in question, convert it to a binary number, compare the numbers (Keeping in mind the differece in lowercase and uppercase numbers), and continue until it is decided which is greater in sorting, then either reconvert the numbers and put them back into the original array, or use an outside read and test to decide where to place the number.
I don't want the code, I just want someone to push me in the right direction or tell me that the above text is a good way of doing it. I'm certain that there is a better way than what I'm thinking, but neither my books nor research are coming up with anything.
Notes: The array will always be devisible by 4. The code will fail if you don't turn lines 96 through 109 to a note. The program will compile and run correctly after that.
/* Author: Anthony Michael
Class: Adv Prog.
Assignment 1: Soccer
------Notes------
outFile.printf or -print would not take my \n command, currently using an added
outFile.println("") to solve this problem.
Exit Code (2) - Random number generated was not between 1-4.
------Methods------
getradnum() = Generates random number
*/
import java.io.*;
public class Ajm01soccer
{
public static void main(String args[]) throws IOException
{
FileReader diskIn = new FileReader("girls40.txt");
BufferedReader inFile = new BufferedReader(diskIn);
FileWriter diskFile = new FileWriter("SoccerAssg1.txt");
PrintWriter outFile = new PrintWriter(diskFile);
String team1[] = new String [20]; //Holds Team1
String team2[] = new String [20]; //Holds Team2
String team3[] = new String [20]; //Holds Team3
String team4[] = new String [20]; //Holds Team4
String temp1[] = new String [20]; //Temporary Array for sorting (For Testing)
int radnum = 0; //Holds Random Number
int slotnum = 0; //Holds for Name Insertion Number
String read1; //Holds First Read Line
String read2; //Holds Second Read Line
String read3; //Holds Third Read Line
String read4; //Holds Forth Read Line
String temp; //Placeholder for temporary storage in sorting
int r = 0; //For sequence in sorting arrays
int reps = 0; //For repetition of sorting arrays
outFile.println("===============================================");
outFile.println("Proj 1 Anthony Michael "); //Import date program
outFile.println("===============================================");
outFile.println(" Lake Wobegon Girl's Soccer League ");
outFile.println("");
outFile.println("No. Team 1 Team 2 Team 3 Team 4 ");
outFile.println("--- ---------- ---------- ---------- ----------");
do
{
//Get 4 names
read1 = inFile.readLine();
read2 = inFile.readLine();
read3 = inFile.readLine();
read4 = inFile.readLine();
System.out.println(read1);
System.out.println(read2);
System.out.println(read3);
System.out.println(read4);
//Random Number Method
radnum = radnumgen();
System.out.println(radnum);
//If statements to determine teams
if (radnum == 1)
{
team1[slotnum] = read1;
team2[slotnum] = read2;
team3[slotnum] = read3;
team4[slotnum] = read4;
}
if (radnum == 2)
{
team1[slotnum] = read4;
team2[slotnum] = read1;
team3[slotnum] = read2;
team4[slotnum] = read3;
}
if (radnum == 3)
{
team1[slotnum] = read3;
team2[slotnum] = read4;
team3[slotnum] = read1;
team4[slotnum] = read2;
}
if (radnum == 4)
{
team1[slotnum] = read2;
team2[slotnum] = read3;
team3[slotnum] = read4;
team4[slotnum] = read1;
}
//Sort Array Method
for (r=0; r<20; r++)
temp1[r] = team1[r];
for(reps=1; reps<20; reps++)
for (r=0; r<19; r++)
if (temp1[r] > temp1[r+1])
{
temp = temp1[r];
temp1[r] = temp1[r+1];
temp1[r+1] = temp;
}
//End Sort Array Method
//Test - Printf format - \n is not forming a new line, outFile.println(""); is being used as a temp.
outFile.printf("%3s %-10s %-10s %-10s %-10s\n",slotnum + ":", team1[slotnum], team2[slotnum], team3[slotnum], team4[slotnum]);
outFile.println("");
//End Test
slotnum++; //Increases the girl number.
}
while(inFile.ready() != false);
//Test
System.out.println(team1[1] + " During test");
System.out.println(team2[1] + " During test");
System.out.println(team3[1] + " During test");
System.out.println(team4[1] + " During test");
for (r=0;r<20;r++)
System.out.println(temp1[r]);
//End Test
outFile.close();
}
public static int radnumgen()
{
int radnum = 0;
radnum = 1 + (int)(Math.random() * 4);
//Random Number Failure
if (radnum > 4 || radnum < 0)
System.exit(2);
//Test - Print rad num
System.out.println(radnum);
return radnum;
}
}
/* Notes-
*/
Attached File(s)
-
girls40.txt (324bytes)
Number of downloads: 36

New Topic/Question
Reply



MultiQuote







|