Results 1 to 1 of 1

Thread: how to save input from a text file in to array

  1. #1
    Join Date
    Mar 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how to save input from a text file in to array

    I got this assignment
    This is what i am suppose to do
    -----------------------------------------------------------------------------------------------------------
    5. The program must store the following data about each student in this Talent Show:
    * The student's name (store as a String)
    * The student's average time score [only for the events they competed in] (store as a Double)

    Note: Some of the data comes directly from the text file, and some of the data must be calculated from the data that is read from the file.

    6. The program must search through all of the student's scores to find the student who has the minumum average time of all students.
    7. You must calculate how many events each student played. Zero values are not counted.
    8. You must then generate a report on the screen that prints out
    * the total number of students in the competition,
    * the winning student's ...
    o name
    o times
    o average time (rounded to one decimal places)

    Sample output

    btw this is the data file
    Bart Simpson
    7.5
    12.3
    7.8
    19.2
    9.9
    5.3
    8.5
    11.8
    2.2
    4.6
    Stewie Griffin
    9.5
    29.7
    7.8
    22.5
    9.9
    12.6
    8.5
    0
    8.2
    0
    Pinky
    2.5
    0
    1.8
    0
    3.9
    0
    6.5
    0
    5.2
    12.1
    Rocky N Bullwinkle
    10.0
    22.2
    9.5
    17.5
    9.9
    1.5
    8.7
    23.7
    9.2
    11.0
    Angelica Pickles
    5.5
    11.1
    6.8
    12.2
    7.9
    13.3
    8.1
    5.1
    7.2
    7.9
    Pink Panther
    8.5
    5.5
    8.8
    6.6
    8.9
    7.7
    9.9
    8.8
    2.2
    9.9
    Josie
    9.5
    0
    8.8
    12.2
    9.9
    0
    8.5
    0
    9.2
    5.3
    Rogue
    8.5
    1.1
    7.8
    2.2
    7.9
    3.3
    7.5
    4.4
    8.2
    5.5
    Usagi Tsukino
    8.5
    15.5
    8.8
    30.1
    9.9
    19.7
    9.5
    11.0
    8.2
    8.6
    Yosemite Sam
    0
    15.2
    0
    29.5
    3.9
    0
    0
    16.0
    0
    7.7
    ----------------------------------------------------------------------------------------------------
    My code so far

    Code:
    import java.io.*;
    
    public class test
    {
        public static void main (String [] args)
        {
    
            FileInputStream File1;
            DataInputStream In;
            String fileInput = "";
    
            try
            {
               File1 = new FileInputStream ("data.txt");
    
    
                In = new DataInputStream (File1);
    
    
                while (In.available () > 0)
                {
                    fileInput = In.readLine ();
                    System.out.println (fileInput);
                }
    
                In.close ();
            }
    
            catch (FileNotFoundException e)
            {
                System.out.println ("Error - this file does not exist");
            }
    
            catch (IOException e)
            {
                System.out.println ("error=" + e.toString ());
            }
    
        }
    }
    My question, how do i save the data in to an array, and how do i seperatly save names in to different array, and their scores in to different arrays

    btw he said you can't use scanner class

    Thanks
    Last edited by supahsain; 03-26-2008 at 11:10 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •