The Artima Developer Community
Sponsored Link

Java Answers Forum
Help please

1 reply on 1 page. Most recent reply: Apr 29, 2002 4:53 AM by Pavan Kumar Keely

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
colin

Posts: 1
Nickname: colywog
Registered: Apr, 2002

Help please Posted: Apr 22, 2002 2:59 AM
Reply to this message Reply
Advertisement
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.


Pavan Kumar Keely

Posts: 7
Nickname: pavan
Registered: Mar, 2002

Re: Help please Posted: Apr 29, 2002 4:53 AM
Reply to this message Reply
> 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

Flat View: This topic has 1 reply on 1 page
Topic: URGENT TicTacToe Application Previous Topic   Next Topic Topic: Retrieving users accounts by Java

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use