How to save input from a text file in to array

I got this assignment, and almost have no clue, and my teacher doesn't even teaches us anything
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
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
bte he said you can use scanner class
Thanks
Edited by: supahsain08 on Mar 26, 2008 2:55 PM

supahsain08 wrote:
Well, you are not in my class and you don't even know my teacher
who are you to judge meHe is jaded by our experiences here. 99% of posters who complain that the teacher doesn't teach have adequate (note that I didn't say good) teachers, but it's the student who is failing to take responsibility for his own education. It is after all your responsibility and complaining won't help you any.
Good luck.

Similar Messages

  • Reading one line from a text file into an array

    i want to read one line from a text file into an array, and then the next line into a different array. both arays are type string...i have this:
    public static void readAndProcessData(FileInputStream stream){
         InputStreamReader iStrReader = new InputStreamReader (stream);
         BufferedReader reader = new BufferedReader (iStrReader);
         String line = "";          
         try{
         int i = 0;
              while (line != null){                 
                   names[i] = reader.readLine();
                   score[i] = reader.readLine();
                   line = reader.readLine();
                   i++;                
              }catch (IOException e){
              System.out.println("Error in file access");
    this section calls it:
    try{                         
         FileInputStream stream = new FileInputStream("ISU.txt");
              HighScore.readAndProcessData(stream);
              stream.close();
              names = HighScore.getNames();
              scores = HighScore.getScores();
         }catch(IOException e){
              System.out.println("Error in accessing file." + e.toString());
    it gives me an array index out of bounds error

    oh wait I see it when I looked at the original quote.
    They array you made called names or the other one is prob too small for the amount of names that you have in the file. Hence as I increases it eventually goes out of bounds of the array so you should probably resize the array if that happens.

  • How to parse data from a text file with no convenient delimiters?

    I need to read data from a text file.  This file contains one line of data with the repeating pattern "time 00 ADVar2: ___ Height: ____ time 01 ADVar2: ___ Height: ___ ..."  I need LabView to parse out the "time" and "height" values, build an array with the values, and graph the correlation on an X&Y plot.  Does Labview have an automated way to read to the input data file and parse out the correct values, even without convenient delimiters?  Thank you.

    You actually do have a convenient delimiter: "time". Thus, you can make an array using that as the delimiter. Only caveat is that the first array element will be empty. Then you can conveniently use the Scan From String function in a for-loop. Something like this:
    Message Edited by smercurio_fc on 11-21-2008 03:13 PM
    Attachments:
    Example_VI.png ‏9 KB

  • How to execute code from a text file?

    Hello all!
    How to execute some code lines from a text file? For example my file is:
    String varname = "somecontents";
    JFrame frame = new JFrame();
    frame.setVisible(true);How can I get contents of this file and parse them if I want get new JFrame and access to the variable varname?

    I mean the PHP would generate a readable Java source,
    for example some variables with some data, and I just
    dont know what to do with file if I want generate the
    xls file from my saved data, could You help? :)Some variables, some data, PHP, Java, XLS file??? Al rather vague.
    You need to explain in more detail what it is you're trying to do if you want an answer to your question!

  • How to build an array based on inputs from a text file

    Hi
    I have ta text file that has the following format. The apmlitude is the first value then I have the start index number and last index number
    Other index values in between should be zero
    (amplitide, start index number, end index number)
    2, 2 ,3
    4, 6, 7
    5, 10,11
    using this format I should make the foloowing array
    0,0,2,2,0,0,4,4,0,0,5,5
    Could you please help me to implement it in LabVIEW
    Thanks

    A few notes:
    - You'll want to use the Initialize Array function for 1) and 3) (if this is, in fact, how you want to do this.)  This function takes two inputs when initializing a 1D array- element value and array size.   
    - Change the polymorphic instance of Read From Spreadsheet File.vi to "Double" or "Integer"- there's no reason to read in these numeric values as strings and convert them later.
    - Will the text file always contain 12 elements worth of data?  If not, you'll need to change your logic for the number of elements to initialize.
    As Altenbach said, this seems a lot like a basic logic/homework problem.  My suggestion was only that-a suggestion.  It is not the only way to do this. Figure out a sequence of steps to get you from point A to point B before you jump in and start coding. 
    Regards,
    Tom L.

  • How do I read from a text file that is longer than 65536 lines and write the data to an Excel spreadshee​t and have the data write to a new column once the 65536 cells are filled in a column?

    I have data that is in basic generic text file format that needs to be converted into Excel spreadsheet format.  The data is much longer than 65536 lines, and in my code I haven't been able to figure out how to carry over the data into the next column.  Currently the conversion is done manually and generates an Excel file that has a total of 30-40 full columns of data.  Any suggestions would be greatly appreciated.
    Thanks,
    Darrick 
    Solved!
    Go to Solution.

    No need to use nested For loops. No need for any loop anyway. You just have to use a reshape array function. The picture below shows how to proceed.
    However, there may be an issue if your element number is not a multiple of the number of columns : zero value elements will be added at the end of the last column in the generated 2D array. Now the issue depends on the way you intend store the data in the Excel spreadsheet : you could convert the data as strings, replace the last zero values with empty strings, and write the whole 2D array to a file (with the .xls extension ) using the write to spreadsheet function. Only one (minimal) problem : define the number of decimal digits to be used;
    or you could write the numeric array directly to a true Excel spreadsheet, using either the NI report generation tools or ActiveX commands, then replace the last elements with empty strings.
    We need more input from you to decide how to solve these last questions. 
    Message Edité par chilly charly le 01-13-2009 09:29 PM
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        
    Attachments:
    Example_VI.png ‏10 KB

  • How to read characters from a text file in java program ?

    Sir,
    I have to read the characters m to z listed in a text file .
    I must compare the character read from the file.
    And if any of the characters between m to z is matched i have to replace it with a hexadecimal value.
    Any help or suggesstions in this regard would be very useful.
    Thanking you,
    khurram

    Hai,
    The requirement is like this
    There is an input file, the contents of the file are as follows, you can assume any name for the file.
    #Character mappings for Japanese Shift-JIS character set
    #ASCII character Mapped Shift-JIS character
    m 227,128,133 #Half width katakana letter small m
    n 227,128,134 #Half width katakana letter small n
    o 227,129,129
    p 227,129,130
    q 227,129,131
    r 227,129,132
    s 227,129,133
    t 227,129,134
    u 227,129,135
    v 227,129,136
    w 227,129,137
    x 227,129,138
    y 227,129,139
    z 227,129,142
    The contents of the above file are to be read as input.
    On encountering any character between m to z, i have to do a replacement with a hexadecimal code point value for the multibyte representation in the second column in the input file.
    I have the code to get the unicode codepoint value from the multibyte representation, but not from a file.
    So if you could please tell me how to get the characters in the second column, it would be very useful for me.
    The character # is used to represent the beginning of a comment in the input file.
    And comment lines are to be ignored while reading the file.
    Say i have a string str="message";
    then i should replace the m with the unicode code point value.
    Thanking you,
    khurram

  • How to import data from a text file into a table

    Hello,
    I need help with importing data from a .csv file with comma delimiter into a table.
    I've been struggling to figure out how to use the "Import from Files" wizard in Oracle 10g web-base Enterprise Manager.
    I have not been able to find a simple instruction on how to use the Wizard.
    I have looked at the Oracle Database Utilities - Overview of Oracle Data Pump and the Help on the "Import: Files" page.
    Neither one gave me enough instruction to be able to do the import successfully.
    Using the "Import from file" wizard, I created a Directory Object using the Create Directory Object button. I Copied the file from which i needed to import the data into the Operating System Directory i had defined in the Create Directory Object page. I chose "Entire files" for the Import type.
    Step 1 of 4 is the "Import:Re-Mapping" page, I have no idea what i need to do on this page. All i know i am not tying to import data that was in one schema into a different schema and I am not importing data that was in one tablespace into a different tablespace and i am not R-Mapping datafiles either. I am importing data from a csv file.
    For step 2 of 4, "Import:Options" page, I selected the same directory object i had created.
    For step 3 of 4, I entered a job name and a description and selected Start Immediately option.
    What i noticed going through the wizard, the wizard never asked into which table do i want to import the data.
    I submitted the job and I got ORA-31619 invalid dump file error.
    I was sure that the wizard was going to fail when it never asked me into which table do i want to import the data.
    I tried to use the "imp" utility in command-line window.
    After I entered (imp), i was prompted for the username and the password and then the buffer size as soon as i entered the min buffer size I got the following error and the import was terminated:
    C:\>imp
    Import: Release 10.1.0.2.0 - Production on Fri Jul 9 12:56:11 2004
    Copyright (c) 1982, 2004, Oracle. All rights reserved.
    Username: user1
    Password:
    Connected to: Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Produc
    tion
    With the Partitioning, OLAP and Data Mining options
    Import file: EXPDAT.DMP > c:\securParms\securParms.csv
    Enter insert buffer size (minimum is 8192) 30720> 8192
    IMP-00037: Character set marker unknown
    IMP-00000: Import terminated unsuccessfully
    Please show me the easiest way to import a text file into a table. How complex could it be to do a simple import into a table using a text file?
    We are testing our application against both an Oracle database and a MSSQLServer 2000 database.
    I was able to import the data into a table in MSSQLServer database and I can say that anybody with no experience could easily do an export/import in MSSQLServer 2000.
    I appreciate if someone could show me how to the import from a file into a table!
    Thanks,
    Mitra

    >
    I can say that anybody with
    no experience could easily do an export/import in
    MSSQLServer 2000.
    Anybody with no experience should not mess up my Oracle Databases !

  • How to save input from radio buttons into textfiles, Help

    Below is my code. Currently it gets the input from the textbox "Date" and places it into a textfile using "getText"
    How do i get the input from a radio button?
    i think getselected only works on JLists.
    String a = bookNo.getText();
              out = new PrintWriter(new FileOutputStream("" + a +".txt"));
    out.println("Date: " + tDate.getText());
    out.close();
    catch(IOException ex)
    System.out.println("Error");
    Your help is appreciated

    Sorry, here's my code. The point of the system is to write information from the page, onto the textfile named "something.txt"
    public void write() {
    String fullfile = "something.txt";
    try {
    BufferedWriter out = new BufferedWriter(new FileWriter(fullfile));
    out.write("");
    out.write("HOLIDAY BOOKING SYSTE,");
    out.write("");
    out.write("SECTION 4.0 DESITNATION");
    out.write("");
    out.write("Holiday Destination: " + list.getSelectedValue());
    out.write("Duration of holiday: ");
    out.write("");
    out.write("SECTION 5.0 TRAVEL RESERVATION DETAILS");
    out.write("Airport for depature and return");
    out.write("Depature Date: " + txtDateD.getText());
    out.write("Depature Time: " + txtTimeD.getText());
    out.write("Arrival Date: " + txtDateA.getText());
    out.write("Arrival Time: " + txtDateA.getText());
    out.write("Holiday Destination: " + txtbookingno.getText());
    out.write("Customer Booking Information");
    out.close();
    } catch (IOException f) {
    //end of file writer
    The code below is for the radio buttons, The choice is to either pay for an "Economic" ticket, or a "First Class" ticket. If a customer selects the economic ticket radio button, what line of coding do i add to the write method above, to show "Economic ticket"
    Also i ran into another slight problem, theres a textbox called "Fine" in another form called "page1", how do i call it's value i.e. what line of code do i place for it in the method above?

  • How to save input and output in file

    hi ni
    i have program that has some input and some output
    i try to save the input and output in file word office or excel like this
    error
    extended
    ideal
    value
    wq
    wp
    value
    xq
    xp
    0.857143
    0.7
    0.6
    2
    0.5
    1
    1
    thank in advace 
    best regards
    m.s
    lab view  2011
    hi ?Q>
    Solved!
    Go to Solution.
    Attachments:
    adder in exteded stochastic.vi ‏37 KB

    johnsold wrote:
    Read from and Write to Spreadsheet File VIs should do what you want.
    I did not take the time to try to decipher what your program is doing, but I think you could replace all those feedback nodes and Build Arrays with an integer data type and the Rotate function from the Numeric >> Data Manipulation palette.  You will still need one shift regsiter or rfeedback node for each of the four signals.
    You have duplicated code: Divide by 65535, multiply by 2, and subtact 1 followed by a > comparison.  Make that a subVI and place 4 instances on your block diagram.
    Those simple changes will make you diagram understandable, reduce its size to the size of a postcard, and make any future changes easier.
    Lynn
    thank
    hi ?Q>

  • Reading dilimited input from a text file with tokenizer

    i am trying to read in a text file with the following structure: 2 integers on each line with comma as the delimitor.
    i am using the BufferedReader stream and Tokenizer to detect ",".
    try {
    BufferedReader in = new BufferedReader(new FileReader(filename));
    //read in the data file
    while ((s = in.readLine())!= null) {
    int i = 0;
    for (i = 0; i < 100; i++) {
    t = new StringTokenizer(s,",");
    A1 = Integer.parseInt(t.nextToken());
    catch (IOException e) {System.err.println(e);}
    When i print out A1[i], it only reads the last line of the text file. Please tell me what's wrong.
    Also i'd really like A1[i] to store the integer before the comma and another array A2[i] to store the integer after the comma. Please help.
    Thanks.
    p.s. A1 and A2 are arrays...when i previewd message in Netscape 7 it left out the brackets and the index....

    What is the for i loop for? If it is to read the next line from the file, then the while loop has taken care of it. Other than this there should be no problem with the rest of the code.
    Just add another line to store the next token into A2.

  • How to import data from a text file through DTS to Sql Server

    Please don't mistake me as i'm a new comer to sql server,please help me.
    how to import the data present in a plain text file through DTS into sql server and store the data in a temporary table.
    How far the temporary table is stored in the database.
    Please reply me as soon as possible.
    Thank you viewers.

    >
    I can say that anybody with
    no experience could easily do an export/import in
    MSSQLServer 2000.
    Anybody with no experience should not mess up my Oracle Databases !

  • How to save data results into text file

    I want to solve an equation of degree 2 for example, and results are displayed in a text file

    Like many other software coding forums, we don't want to give hand outs.  We are more than happy to give hand ups.  Show that you've tried to figure out the problem and show us where you are stuck.  Then we will be glad to help you get you unstuck.  If we just give you an answer, you will learn nothing.
    As far as writing to a text file, look in the File I/O palette for the Write to Text File primitive.  Also, if you go to Help->Find Examples... and do a search for "text file" you will get some examples of how to use it.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • How to read data from a text file

    I have saved a text file on my hard drive, and would like to read the file. Once read I would like to copy it to another file. I think I am suppose to use the BufferedReader, and FileReader classes. I am not sure what sequence to follow in order to do this. Could some one give me some feed back on what is needed, and in what sequence to perform this task?

    Where do I store my file within my Platform(Eclipe), in order to read or access the file. Whenever I use the declaration below. I get an FileNotFoundException. I understand the code, but am not sure where to store the file, so that the line of code below will recognize it..
    FileReader in = new FileReader("data1.txt");
              BufferedReader a = new BufferedReader(in);

  • Converting a text file into an array

    import java.io.*;
    public class Copy {
    public static void main(String[] args) throws IOException {
         File inputFile = new File("farrago.txt");
         File outputFile = new File("outagain.txt");
    FileReader in = new FileReader(inputFile);
    FileWriter out = new FileWriter(outputFile);
    int c;
    while ((c = in.read()) != -1)
    out.write(c);
    in.close();
    out.close();
    i have been working my way through the online tutorials and have found them very helpful, i have looked at array and would like to know how to convert data from a text file inot an array? using the above example how would i go about doing this?

    You'd use the readLine () method:BufferedReader reader = new BufferedReader (new FileReader (file));
    String line;
    List list = new LinkedList ();
    while ((line = reader.readLine ()) != null) {
        list.add (line);
    // don't know why you'd want this, but anyway
    String[] lines = (String[]) list.toArray (new String[list.size ()]);Kind regards,
      Levi

Maybe you are looking for