Question

Can someone help with the java code? (A city data file) ----------------------------------------------------------------------------- Louisiana LA Kenner 6387 21.7 19 24.4 30.0264774449 -90.242590737...

Can someone help with the java code?

(A city data file)

-----------------------------------------------------------------------------

Louisiana

LA

Kenner

6387 21.7 19 24.4 30.0264774449 -90.2425907379 1

------------------------------------------------------------------------------

Data in these city files is organized as follows:

i. Line one contains the name of the state of the city.

ii. Line two contains the abbreviation of the state of the city.

iii.Line three contains the name of the city.

iv. Lines four and all the lines that follow are organized in fields of numbers, each separated by a single space, essentially making columns of data in the file. These fields are:

A. field 1: sample size int; the number of people in the area sampled

B. field 2: percentage double; the percent result of the survey; stored in the form ##.# (example 50.2 is 50.2 percent)\

C. field 3: lower confidence double; the lower bounds of confidence in the percentage; stored in the form ##.# (example 50.2 is 50.2 percent)

D. field 4: upper confidence double; the upper bounds of confidence in the percentage; stored in the form ##.# (example 50.2 is 50.2 percent)

E. field 5: latitude central latitude of the sample area

F. field 6: longitude central longitude of the sample area

G. field 7: measure key the code (key) of the measure of the survey results

Make a class to hold one line of survey data for a city.

1. The survey data is found on lines four to a city file’s end.

2. This will be an immutable class. This means it has no setter (mutator) methods, only fields, constructors and getter (accessor) methods.

3. Create the class and file in the project as usual, then (a) add a private field for each of the seven fields on line four (and beyond) of a city file as described above (b) Add a constructor that accepts the values for the fields and assigns valid values. The limits are as follows. i. sample size must be 0 or greater ii. percentage, lower confidence and upper confidence must be in the range [0, 100], i. e. 0 to 100 inclusive iii.latitude must be in the range [25,50], i. e. 25 degrees north to 50 degrees north to belong to a city in the “lower 48” states iv. longitude must be in the range [-65,-130], i. e. -65 degrees to -130 degrees to belong to a city in the “lower 48” states; negative longitudes indicate west of the prime meridian v. measure key must be a value in the range [1,28], i. e. 1 to 28 inclusive (c) create a getter (accessor) for each of the private data fields (d) as a parametrized constructor exists, a default constructor must be created, even if it is empty of any code

-------------------survey.txt -------------------

Current lack of health insurance among adults aged 18–64 Years

Arthritis among adults aged >=18 Years Binge drinking among adults aged >=18 Years

High blood pressure among adults aged >=18 Years

Taking medicine for high blood pressure control among adults aged >=18 Years with high blood pressure

Stroke among adults aged >=18 Years

Cancer (excluding skin cancer) among adults aged >=18 Years

Current asthma among adults aged >=18 Years Coronary heart disease among adults aged >=18 Years

Visits to doctor for routine checkup within the past Year among adults aged >=18 Years

Cholesterol screening among adults aged >=18 Years Fecal occult blood test sigmoidoscopy or colonoscopy among adults aged 50–75 Years

Chronic obstructive pulmonary disease among adults aged >=18 Years

Older adult men aged >=65 Years who are up to date on a core set of clinical preventive services: Flu shot past Year PPV shot ever

Colorectal cancer screening Older adult women aged >=65 Years who are up to date on a core set of clinical preventive services: Flu shot past Year PPV shot ever

Colorectal cancer screening and Mammogram past 2 Years Current smoking among adults aged >=18 Years

Visits to dentist or dental clinic among adults aged >=18 Years Diagnosed diabetes among adults aged >=18 Years

High cholesterol among adults aged >=18 Years who have been screened in the past 5 Years

Chronic kidney disease among adults aged >=18 Years No leisure-time physical activity among adults aged >=18 Years Mammography use among women aged 50–74 Years

Mental health not good for >=14 days among adults aged >=18 Years

Obesity among adults aged >=18 Years

Papanicolaou smear use among adult women aged 21–65 Years

Physical health not good for >=14 days among adults aged >=18 Years

Sleeping less than 7 hours among adults aged >=18 Years

All teeth lost among adults aged >=65 Years

0 0
Add a comment Improve this question Transcribed image text
Answer #1

please find java file and text data file below, thanks...

//-------- CityDataTest.java
import java.io.*;
import java.util.*;

class CityData {
  
//following three fields are not specified so commented, can be deleted
/* private String state;
private String stAbbr;
private String city; */

private int sampleSize;
private double perResult;
private double lowerConf;
private double upperConf;
private double latitude;
private double longitude;
private int measureKey;

CityData()
{
   }

CityData(int ss, double pr, double low, double up, double lat, double lon, int mk) {

if (ss >= 0)
sampleSize = ss;
else
System.out.println("Invalid sample size");

if (pr >= 0 && pr <= 100)
perResult = pr;
else
System.out.println("Invalid result percentage");

if (low >= 0 && low <= 100)
lowerConf = low;
else
System.out.println("Invalid lower confidence");

if (up >= 0 && up <= 100)
upperConf = up;
else
System.out.println("Invalid upper confidence");

if (lat >= 25 && lat <= 50)
latitude = lat;
else
System.out.println("Invalid latitude");

if (lon >= -130 && lon <= -65)
longitude = lon;
else
System.out.println("Invalid longitude");

if (mk >= 1 && mk <= 28)
measureKey = mk;
else
System.out.println("Invalid longitude");

}

public int getsampleSize() {
return sampleSize;
}
public double getperResult() {
return perResult;
}
public double getlowerConf() {
return lowerConf;
}
public double getupperConf() {
return upperConf;
}
public double getlatitude() {
return latitude;
}
public double getlongitude() {
return longitude;
}
public int getmeasureKey() {
return measureKey;
}

public void display() // extra method to display data, you can delete it if not required
{
System.out.println("sampleSize " + sampleSize);
System.out.println("perResult " + perResult);
System.out.println("lowerConf " + lowerConf);
System.out.println("upperConf " + upperConf);
System.out.println("latitude " + latitude);
System.out.println("longitude " + longitude);
System.out.println("measureKey " + measureKey);
System.out.println(); //print blank line
}

}

public class CityDataTest {

public static void main(String args[]) {
readData("cityData.txt");

}

public static void readData(String filename) {   //method to read data from file to CityData objects
      
List < CityData > allData = new ArrayList < CityData > (); //list of all CityData

CityData tempData = null; // to store CityData of each line

String state;
String stAbbr;
String city;

int sampleSize = -1;
double perResult = -1;
double lowerConf = -1;
double upperConf = -1;
double latitude = -1;
double longitude = -1;
int measureKey = -1;

try {
// Open the file
FileInputStream fstream = new FileInputStream(filename);
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
String strLine;

//Read File Line By Line
while ((strLine = br.readLine()) != null) {
state = strLine; // read state name

strLine = br.readLine();
stAbbr = strLine; // read state abbrivation

strLine = br.readLine();
city = strLine; // read city name

System.out.println("Reading data for:");
System.out.println(state);
System.out.println(stAbbr);
System.out.println(city);

while ((strLine = br.readLine()) != null) { // now read data lines
System.out.println(strLine);
String[] data = strLine.split(" "); //separate data by space

if (data.length >= 7) // if line contains all 7 fields then read them
{
sampleSize = Integer.parseInt(data[0]);
perResult = Double.parseDouble(data[1]);
lowerConf = Double.parseDouble(data[2]);
upperConf = Double.parseDouble(data[3]);
latitude = Double.parseDouble(data[4]);
longitude = Double.parseDouble(data[5]);
measureKey = Integer.parseInt(data[6]);
}

tempData = new CityData(sampleSize, perResult, lowerConf, upperConf, latitude, longitude, measureKey);
allData.add(tempData);
tempData.display();

}
}

} catch (Exception e) {
System.out.println(e);
}
}

}
//-------- end of CityDataTest.java


//------ cityData.txt   put this file in same directory as java file
Louisiana
LA
Kenner
6387 21.7 19 24.4 30.0264774449 -90.2425907379 1
1234 121.7 119 124.4 20.0264774449 -60.2425907379 2
//------ end of cityData.txt
last data line has wrong data to test

Add a comment
Know the answer?
Add Answer to:
Can someone help with the java code? (A city data file) ----------------------------------------------------------------------------- Louisiana LA Kenner 6387 21.7 19 24.4 30.0264774449 -90.242590737...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT