Hey guys, I'm quite new to Java and I usually try to get things done on my own, but it seems like I'm just sooo lost now.
Would really appreciate any help you guys can give me
So here's the problem:
I need my program to read a text file called "osaka.txt" which basically has a list of 7 Heats, in each heat there are 8 athletes and every Athlete has information such as Lane, Number, Name, Nationality and Time. It is all set out neatly in rows and columns.
So basically what i have tried to do is to use 2 different reading methods, and find out which is the best method to read the file.
The first method is :
import java.io.*;
class Heat
{
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("osaka.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null)
{
System.out.println (strLine);
}
in.close();
}
catch (Exception exc)
{
System.err.println("Error: " + exc.getMessage());
}
}
}
and the 2nd method is:
import java.io.*;
public class Heat2 {
public static void main(String[] args)
{
try
{
File file = new File("osaka.txt");
FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
DataInputStream dis = new DataInputStream(bis);
while (dis.available() != 0)
{
System.out.println(dis.readLine());
}
fis.close();
bis.close();
dis.close();
}
catch (FileNotFoundException exc)
{
System.err.println("Error: " + exc.getMessage());
}
catch (IOException exc)
{
System.err.println("Error: " + exc.getMessage());
}
}
}
So now where I am stuck at is, how to create a class which contains the information about 8 athletes in one heat, meaning I would need to create an array for the athletes.
What i think then is to have a method which would read the data file for one heat by itself, and from there pick out the 3 fastest runners.
This is because later on I will need to pick out the 3 fastest 3 runners from each Heat, and the 3 "2nd fastest" runners and put them into the next round.
I think I am Ok with sorting the arrays of the athletes in terms of their running time, but I need some help in creating arrays for the athletes in every heat. Been trying to do it for more than a week now and still stuck, maybe because I am quite new to Java and am looking at it the wrong way.
Lastly, I will need to list the 24 athletes who make it to the next round, but I hope I can do that once I get the arrays done.
Not sure if I'm allowed to upload the text file so you guys can have a look at it or not, but here it is: http://www.mediafire.com/file/dx3qyww0wqy/osaka.txt
Sorry for violating any rules if I am.
Thanks for any help, would really be grateful for it ;-)