Okay. I apologise if this is in the wrong section ^^
The assignment that I have been given asks me to use a .txt file (that contains 7 heats, each with 8 runners with their times, nationalities, numbers etc) and read it contents, I have to take the various values (names, times, nationalities etc) and store them suitably in an Array. I then have to present a way to print out the data in particular order...ie. Runners who have the fastest time.
This may sound odd and I would like to clarify that I do NOT want this 'completed for me'.
All I require are the tools so I can do it myself ^^
My tutor was very vague in regards to using the FileReader and I'm having trouble getting it to work.
I can't seem to work it out, not only that but I need to store Ints, Floats and Strings.
My plan is to store all the standard info (name, nat, etc) as Strings in a 2-D array.
ie. Array [1][7] will give me the info for the first heat and runner number 7 (I'm ignoring array 0 for ease of access).
But, to help do this, when I ever get the FileReader to work I will also need to be able to skip over values in the .txt file so that I am able to store their Race Times in a separate array of doubles.
Follow me so far?
Okay, well, I guess I'll post up my code...its 'bitty' atm, but I'd ask you to direct your attention to the class times, thats where I'm working first of all (to get used to FileReader I'll work on storing the TIMEs as doubles to begin with)
Please be gentle with me -- I've only be studying this for a few months ^^
The txt file: osaka.txt (also saved as a .dat)package coursework1; import java.io.FileNotFoundException; import java.io.FileReader; import java.util.Scanner; public class Main { public static void main(String[] args) throws FileNotFoundException { //TO DO/////////////////////////////////// //READ IN DATA and STORE // //PRINT DATA // //PRINT Fastest 3 Runners from Each Heat// ////////////////////////////////////////// Main.times(args); // FileReader frName = new FileReader("osaka.dat"); // Scanner infile = new Scanner (frName); // // String test = infile.nextLine(); // System.out.println(test); // infile.close(); } public static void athlete(String[] args) throws FileNotFoundException { String[][] HeatNfo = new String[8][9]; // FileReader frName = new FileReader("osaka.txt"); // Scanner infile = new Scanner (frName); // // String test = infile.nextLine(); // System.out.println("Test"); // infile.close(); } public static void times(String[] args) throws FileNotFoundException { //Read in times and store them in an array int[][] HeatTime = new int[8][9]; FileReader frTime = new FileReader("osaka.txt"); Scanner infile = new Scanner(frTime); for (int counter = 0; counter < 25; counter++) { //infile.skip(long n); HeatTime[0][counter] = infile.nextInt(); } infile.close(); } {//Array of Strings. //First array postion will store the heats. //The next array within this will store the racers within the heats. //The third directory in the array will store the racers info in this order: //Lane, Num, Name and Nat. //For example: [2][7][3] will return Heat 2, Racer 7, Name (Martyn Rooney) //I will store the times in another class seperatly as Doubles. } public static void display(int x[][]) { for (int row = 0; row < x.length; row++) { for (int column = 0; column < x[row].length; column++) { System.out.print(x[row][column] + "\t"); } System.out.println(); } } //This will display all results in a 2-D Array }
Heat 1 Lane num Name Nat Time 1 334 John Steffensen AUS 44.82 2 500 Takeshi Fujiwara ESA 46.92 3 651 Dim�trios R�gas GRE 46.22 4 352 Chris Brown BAH 44.5 5 1050 Rennyuow TRI 45.7 6 491 Arismendy Peguero DOM 44.92 7 897 Marcin Marciniszyn POL 45.83 8 626 Bastian Swillims GER 45.44 Heat 2 Lane num Name Nat Time 1 351 Avard Moncur BAH 45.27 2 571 Brice Panel FRA 46.02 3 1166 Lewis Banda ZIM 45.47 4 915 F�lix Mart�nez PUR 46.86 5 1151 Jeremy Wariner USA 45.1 6 684 David Gillick IRL 45.35 7 595 Martyn Rooney GBR 45.47 8 846 Herm�n L�pez NCA 50.72 Heat 3 Lane num Name Nat Time 1 905 Rafal Wieruszewski POL 45.94 2 489 Carlos Santa DOM 45.99 3 658 Alleyne Francique GRN 44.95 4 1001 Abdulla Mohamed Hussei SOM 50.54 5 713 Ricardo Chambers JAM 45.34 6 561 Leslie Djhone FRA 45.17 7 345 Clemens Zeller AUT 46.06 8 596 Andrew Steele GBR 45.54 Heat 4 Lane num Name Nat Time 1 349 Andrae Williams BAH 45.31 2 1037 Johan Wissman SWE 44.94 3 1080 Andr�s Silva URU 46.79 4 1120 LaShawn Merritt USA 44.78 5 1168 Young Talkmore Nyongan ZIM 45.4 6 834 Dalibor Spasovski MKD 48.63 7 381 Gakologelwang Masheto BOT 0.0 8 842 Eric Milazar MRI 46.55 Heat 5 Lane num Name Nat Time 1 584 Timothy Benjamin GBR 45.44 2 451 Gary Kikaya COD 45.21 3 313 Nicolau Palanca ANG 48.6 4 486 Chris Lloyd DMA 45.46 5 932 Ioan Lucian Vieru ROM 46.78 6 706 Sanjay Ayre JAM 45.28 7 954 Vladislav Frolov RUS 45.69 8 366 Mathieu Gnaligo BEN 47.51 Heat 6 Lane num Name Nat Time 1 708 Michael Blackwood JAM 45.44 2 1141 Angelo Taylor USA 45.13 3 735 Yuki Yamaguchi JPN 46.28 4 380 California Molefe BOT 45.36 5 455 Nery Brenes CRC 45.01 6 646 Jonathon Lavers GIB 47.97 7 999 Ivano Bucci SMR 48.07 8 459 William Collazo CUB 45.29 Heat 7 Lane num Name Nat Time 1 1049 Ato Modibo TRI 45.22 2 891 Daniel Dabrowski POL 45.5 3 329 Sean Wroe AUS 45.39 4 649 Dim�trios Gr�valos GRE 46.94 5 1161 Moses Kamut VAN 48.9 6 690 Andrea Barberi ITA 45.74 7 1114 Lionel Larry USA 0.0 8 425 Tyler Christopher CAN 45.15
...and to save confusion...THIS is my assignment.
Hopefully it will make more sense than my own ramblings...
ECSC401 Programming Methodology (Java) Semester 1, 2009/10 Coursework Deadline : Tuesday 12th January 2010 Value : 20 marks Requirements The results of the mens 400m heats from the 2007 IAAF World Championships in Osaka have been stored in the file osaka.txt. For each heat, the file contains the following information about each athlete: • lane number • competition number {worn on vest} • name • nationality {3 character abbreviation} • time for the race {seconds} The fastest three athletes from each heat automatically qualified for the next round, along with the three overall fastest "losers", so that 24 athletes progressed to the next round of the competition. You are asked to write, in Java : • a method to read the data from the file and store it in a suitable way. • a method which lists the fastest three athletes from one heat. • a main method which uses these two methods and establishes which twenty four athletes would progress to the next round of the competition. N.B. It is likely that you will need a few more methods to complete this task. You should hand in the following at the campus office: • A listing of your java program. • A test plan describing the tests that you ran on the program and their results. Please do not include discs! They are not needed thank you. Marks will be lost if you do not follow the Department Coding Standard for code layout. You should also email the java source code to your tutor: • Cavendish Chris Bailey • Harrow Artie Basukoski
Thanks in advance for any help and advice