473,396 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2.  
  3. public class test
  4. {
  5.     public static void main (String [] args)
  6.     {
  7.  
  8.         FileInputStream File1;
  9.         DataInputStream In;
  10.         String fileInput = "";
  11.  
  12.         try
  13.         {
  14.            File1 = new FileInputStream ("data.txt");
  15.  
  16.  
  17.             In = new DataInputStream (File1);
  18.  
  19.  
  20.             while (In.available () > 0)
  21.             {
  22.                 fileInput = In.readLine ();
  23.                 System.out.println (fileInput);
  24.             }
  25.  
  26.             In.close ();
  27.         }
  28.  
  29.         catch (FileNotFoundException e)
  30.         {
  31.             System.out.println ("Error - this file does not exist");
  32.         }
  33.  
  34.         catch (IOException e)
  35.         {
  36.             System.out.println ("error=" + e.toString ());
  37.         }
  38.  
  39.     }
  40. }
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
Mar 26 '08 #1
1 2764
Ganon11
3,652 Expert 2GB
I would have maybe an ArrayList of arrays, or ArrayList of ArrayLists...the first dimension must be dynamic (i.e. you don't know how many participants there will be).

When you read in a line, you have it as a String. Then you can use the parseInt method to check if you got a new name or a number. If it's a number, then it's another event score/time for the current participant, and you can add the value to the current ArrayList. If it's a new name, you build a new ArrayList and start modifying that (after finalizing the last ArrayList you were working on).

You may want to create your own class, like Racer, which will have the name (String) and an array/ArrayList of the scores. This means you can have an ArrayList of Racers, and will simplify your code somewhat.
Mar 26 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: BadOmen | last post by:
I have a text file that I want to save from my program. But I don't want to save the empty lines. I want to delete everything after the last character, Is that possible? Then when I read the...
4
by: Andras Gilicz | last post by:
Hi VB fans I'm working on a relatively large project in VB6 with about a dozen forms, including graphs, labels, text boxes, etc. The software itself is actually a flow simulator with more or...
4
by: oncelovecoffee | last post by:
str_Array() 'strings I need save it to file and next time i can read from file. --------------------------------------------------------...
8
by: david.lindsay.green | last post by:
Hello all, I am quite new a web scripting and making web pages in general and I have stumbled across a problem I have as yet been unable to solve. I am trying to take the contents of a textarea box...
0
by: amrhi | last post by:
Hy Guys , Can anybody help me ? I try to make small web database in my unit. Some of fields have on change behaviour to get other data that automatically filled other text field. But when i try to...
11
by: Lamer | last post by:
I was wondering how to save PHP variables to a txt file and then retrieve them again. Example: There is an input box, after submitted the stuff that was written in the input box will be saved...
6
by: john | last post by:
I have the following textbox setup with Text & ToolTip Bindings as follows; I'm using Visual Studio 2008 VB: <asp:TextBox ID="txtDay1" runat="server" Text='<%# Eval("Day1") %>'...
2
by: simonyong | last post by:
Hello, anyone I had search for few days with how to save file when user choose a file name from listbox and i will search the file from database and user can save it into their desktop what I had...
1
by: chennaibala | last post by:
can any one send me mutiple image upload program and save the file name with extension in mysql table.we must cheak uploaded file type like bmp or any image file while uploading. i develop...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.