|
Re: Help please
|
Posted: Apr 29, 2002 4:53 AM
|
|
> I am having trouble getting started can anyone help > me out? > A text file on the internet contains the results of a > survey of the age, height and weight of some > population. The first line of the file is the number > of people surveyed, following this are lines of the > format: > age, height, weight > Each sample is on a separate line with values being > comma and space seperated, , an example of a file?s > contents is > 3 > 25, 1.8, 10.5 > 40, 1.78 ,12.8 > 31, 1.52, 11.3 > You are to develop a Java application (NOT an applet) > to display the average age, height and weight from > the data supplied in such an internet file. > Application Requirements > 1. The URL of the required internet file should be > supplied to the aplication as a command-line > argument. If no URL is supplied then the user should > be prompted to enter one. > 2. If the file cannot be accessed then an appropriate > error message should be displayed. > 3. A class should be defined to model a single sample > (i.e. the age, height & weight of one individual) > with methods to retrieve each seperate data value. > 4. A class should be defined to model the set of > survey data; the attribute of this class should be an > array of the objects described above. The methods of > this class should return (not display) the average > age, height & weight from the set of data. > 5. The application should process the URL file name, > create a survey data object (and hence the sample > data objects) and access this object in order to > display the appropriate output. > 6. The output from the application should display the > name of the file used, the total number of people > surveyed and the average age, height and weight of > the surveyed individuals. > Initially you may assume that the file contains only > valid data.
hi...
take the URLConnection class to get the file and establish the DataInputStream for the inputstream of URLConnection.
read lines and for every line you read.....take the first string before the "," and convert that string to int and add that int to a local variable ageSum....and take the count of lines read (say total).....after reading all the lines .....just calculate ageSum/total.... that'll give the average......
If you have any doubt feel free to contact me at keelypavan@hotmail.com
bye and good luck
|
|