Input data file and 2D array containing data The data file is in csv (comma separated values) format. Files in csv format are plain text files that store data by delimiting data entries with commas.   The data file has the following format: 1 line containing an integer with the number of communities in the file, call this number n. n lines of communities. Each line contains 22 values with the following information about the community: the percentage (value between 0 and 1.0) of  Black people. the percentage (value between 0 and 1.0) of American Indian and Alaska Native people. the percentage (value between 0 and 1.0) of Asian people. the percentage (value between 0 and 1.0) of Native Hawaiian and Pacific people. the percentage (value between 0 and 1.0) of people with two or more races. the percentage (value between 0 and 1.0) of White people. the percentage (value between 0 and 1.0) of Hispanic or Lantix. the percentage (value between 0 and 1.0) of other races not listed. the percentage (value between 0 and 1.0) of people under 10 years old. the percentage (value between 0 and 1.0) of people between 10 and 64 years old. the percentage (value between 0 and 1.0) of people over 64 years old. the total number of people in the community. the percentage (value between 0 and 1.0) of properties at risk of flood in 30 years. the percentage (value between 0 and 1.0) of properties at risk of fire in 30 years. the PM 2.5 level in the air. the number of people (18 or older) with asthma. the number of people (18 or older) with diabetes. the number of people (18 or older) with heart disease. life expectancy. the percentage (value between 0 and 1.0) of unemployment. contains the value 1 if the community is low income, 0 (zero) otherwise. contains the value 1 if the community is identified as disadvantaged, 0 (zero) otherwise. Here is an example of the file format. The sample file below contains 3 lines. The first line contains the number of communities (2) Then 2 lines. Each representing one community. The first community contains 1993 people, of which 83% are white. 990 people in this community have asthma.    We provide the function readDataFromFile() that reads the input file and stores its content into a 2D array of double values.   In the 2D array: each row contains to one community. each column contains the values from the input file, in the order provided above. The 2D array below shows the 2 communities (one per row), which contains the percentage of the population that is Hispanic or Latinx at index 6, the number of people with asthma at index 15, and so on. The columns have the same order as the data file.   To facilitate handling the columns, we provide (in Communities.java) variables to identify each column index. Here are the variables that appear in the figure below. Refer to the file for all variables. RD_HISP_OR_LATINO is index 6 HLT_ASTHMA is index 15 ECON_LOW_INCOME is index 20 ECON_DISADVANTAGED is index 21   Functions implemented by you: The double 2D array containing the data is passed as the first argument to each of the functions that you will implement in this assignment.   1. getPM25Level(double[][] data, int community) This function returns the PM2.5 level in the air for the community at row index community.   2. findAverageLifeExpectancy(double[][] data) This function computes and returns the average life expectancy amongst all communities in the data array.   3. highestPopulationWithHealthIssue (double[][] data, char healthIssue) This function finds the community that contains the highest number of cases of a certain health issue and returns the number of cases. The healthIssue parameter will be one of the following characters: ‘A’ asthma ‘D’ diabetes ‘H’ hearth disease 4. numberOfCommunities (double[][] data, int columnIndex, double percentageThreshold, boolean isDisadvantage) Finds and returns the number of communities that have a percentage of a racial demographic (at columnIndex) population higher than or equal to a threshold (percentageThreshold). Consider only disadvantaged communities if the parameter isDisadvantage is true, otherwise consider only non-disadvantaged communities. The threshold is a number between 1 and 100. The file contains numbers between 0 and 0.100 5. largestRacialDemographic(double[][] data, int community) Returns the percentage (value between 0 and 100) of the largest racial demographic in the community at row index community.   6. mostPopulatedDisadvantagedWithLowIncome(double[][] data) Returns the community (row index) with the largest population that is low income and disadvantaged. We provide 2 input files in the zip file. CommunitiesData.csv with 64632 communities, and SampleCommunitiesData.csv with 18 communities. Executing the main() function with SampleCommunitiesData.csv as the input file yields. java Communities

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter9: Using Classes And Objects
Section: Chapter Questions
Problem 20RQ
icon
Related questions
Question

Input data file and 2D array containing data

The data file is in csv (comma separated values) format. Files in csv format are plain text files that store data by delimiting data entries with commas.
 
The data file has the following format:
  • 1 line containing an integer with the number of communities in the file, call this number n.
  • n lines of communities. Each line contains 22 values with the following information about the community:
    • the percentage (value between 0 and 1.0) of  Black people.
    • the percentage (value between 0 and 1.0) of American Indian and Alaska Native people.
    • the percentage (value between 0 and 1.0) of Asian people.
    • the percentage (value between 0 and 1.0) of Native Hawaiian and Pacific people.
    • the percentage (value between 0 and 1.0) of people with two or more races.
    • the percentage (value between 0 and 1.0) of White people.
    • the percentage (value between 0 and 1.0) of Hispanic or Lantix.
    • the percentage (value between 0 and 1.0) of other races not listed.
    • the percentage (value between 0 and 1.0) of people under 10 years old.
    • the percentage (value between 0 and 1.0) of people between 10 and 64 years old.
    • the percentage (value between 0 and 1.0) of people over 64 years old.
    • the total number of people in the community.
    • the percentage (value between 0 and 1.0) of properties at risk of flood in 30 years.
    • the percentage (value between 0 and 1.0) of properties at risk of fire in 30 years.
    • the PM 2.5 level in the air.
    • the number of people (18 or older) with asthma.
    • the number of people (18 or older) with diabetes.
    • the number of people (18 or older) with heart disease.
    • life expectancy.
    • the percentage (value between 0 and 1.0) of unemployment.
    • contains the value 1 if the community is low income, 0 (zero) otherwise.
    • contains the value 1 if the community is identified as disadvantaged, 0 (zero) otherwise.

Here is an example of the file format. The sample file below contains 3 lines.

  • The first line contains the number of communities (2)
  • Then 2 lines. Each representing one community. The first community contains 1993 people, of which 83% are white. 990 people in this community have asthma. 
 
We provide the function readDataFromFile() that reads the input file and stores its content into a 2D array of double values.
 
In the 2D array:
  • each row contains to one community.
  • each column contains the values from the input file, in the order provided above.
The 2D array below shows the 2 communities (one per row), which contains the percentage of the population that is Hispanic or Latinx at index 6, the number of people with asthma at index 15, and so on. The columns have the same order as the data file.
 
To facilitate handling the columns, we provide (in Communities.java) variables to identify each column index. Here are the variables that appear in the figure below. Refer to the file for all variables.
  • RD_HISP_OR_LATINO is index 6
  • HLT_ASTHMA is index 15
  • ECON_LOW_INCOME is index 20
  • ECON_DISADVANTAGED is index 21
 

Functions implemented by you:

The double 2D array containing the data is passed as the first argument to each of the functions that you will implement in this assignment.
 
1. getPM25Level(double[][] data, int community)
This function returns the PM2.5 level in the air for the community at row index community.
 

2. findAverageLifeExpectancy(double[][] data)

This function computes and returns the average life expectancy amongst all communities in the data array.

 
3. highestPopulationWithHealthIssue (double[][] data, char healthIssue)
This function finds the community that contains the highest number of cases of a certain health issue and returns the number of cases. The healthIssue parameter will be one of the following characters:
  • ‘A’ asthma
  • ‘D’ diabetes
  • ‘H’ hearth disease
4. numberOfCommunities (double[][] data, int columnIndex, double percentageThreshold, boolean isDisadvantage)
Finds and returns the number of communities that have a percentage of a racial demographic (at columnIndex) population higher than or equal to a threshold (percentageThreshold). Consider only disadvantaged communities if the parameter isDisadvantage is true, otherwise consider only non-disadvantaged communities.
  • The threshold is a number between 1 and 100. The file contains numbers between 0 and 0.100
5. largestRacialDemographic(double[][] data, int community)
Returns the percentage (value between 0 and 100) of the largest racial demographic in the community at row index community.
 
6. mostPopulatedDisadvantagedWithLowIncome(double[][] data)
Returns the community (row index) with the largest population that is low income and disadvantaged.

We provide 2 input files in the zip file. CommunitiesData.csv with 64632 communities, and SampleCommunitiesData.csv with 18 communities.

Executing the main() function with SampleCommunitiesData.csv as the input file yields.

java Communities

*/
public static double [] [] readDataFromFile (String dataFile) {
}
StdIn. setFile(dataFile);
String[] line = StdIn.readLine().split(regex:",");
int nbrCommunities = Integer.parseInt(line [0]);
// create the array to hold the data
double [] [] cData = new double [nbrCommunities] [22];
for (int c = 0; c < nbrCommunities; c++ ) {
// Each line contains the data for ONE community.
// Reads one line, extracting each comma separated field.
String [] oneCommunity = StdIn.readLine().split(regex:",");
// Store the data into the array
// racial demographics
// opens the file to read
cData [c] [RD_BLACK]
= Double.parseDouble (oneCommunity [RD_BLACK]);
cData [c] [RD_NATIVE_AMERICAN] = Double.parseDouble (one Community [RD_NATIVE_AMERICAN] );
cData [c] [RD_ASIAN]
= Double.parseDouble (one Community [RD_ASIAN]);
= Double.parseDouble (one Community [RD_NATIVE_HAWAIAN]);
cData [c] [RD_NATIVE_HAWAIAN]
cData [c] [RD_TWO_OR_MORE]
cData [c] [RD_WHITE]
= Double.parseDouble (oneCommunity [RD_TWO_OR_MORE]);
= Double.parseDouble (one Community [RD_WHITE]);
= Double.parseDouble (oneCommunity [RD_HISP_OR_LATINO]);
= Double.parseDouble (oneCommunity [RD_OTHER]);
cData [c] [RD_HISP_OR_LATINO]
cData [c] [RD_OTHER]
// age
cData [c] [AGE_UNDER_10] = Double.parseDouble (oneCommunity [AGE_UNDER_10]);
cData [c] [AGE_10_TO_64] = Double.parseDouble (oneCommunity [AGE_10_TO_64]);
cData [c] [AGE_OVER_64] = Double. parseDouble (one Community [AGE_OVER_64]);
cData [c] [TOTAL_POPULATION] = Double.parseDouble (oneCommunity [TOTAL_POPULATION]);
// health
= Double.parseDouble (oneCommunity [HLT_PM2_5]);
cData [c] [HLT_FLOOD_RISK] = Double.parseDouble (oneCommunity [HLT_FLOOD_RISK]);
cData [c] [HLT_FIRE_RIST] = Double.parseDouble (oneCommunity [HLT_FIRE_RIST]);
cData [c] [HLT_PM2_5]
cData [c] [HLT_ASTHMA]
cData [c] [HLT_DIABETES]
cData [c] [HLT_HEART_DISEASE]
cData [c] [HLT_LIFE_EXPECT]
= Double.parseDouble (one Community [HLT_ASTHMA]);
= Double.parseDouble (one Community [HLT_DIABETES]);
= Double.parseDouble (oneCommunity [HLT_HEART_DISEASE] );
= Double.parseDouble (oneCommunity [HLT_LIFE_EXPECT]);
cData [c] [ECON_UNEMPLOYEMENT] = Double.parseDouble (one Community [ECON_UNEMPLOYEMENT] );
cData [c] [ECON_LOW_INCOME] = Double.parseDouble (oneCommunity [ECON_LOW_INCOME]);
cData [c] [ECON_DISADVANTAGED] = Double.parseDouble (one Community [ECON_DISADVANTAGED] );
}
return cData;
Transcribed Image Text:*/ public static double [] [] readDataFromFile (String dataFile) { } StdIn. setFile(dataFile); String[] line = StdIn.readLine().split(regex:","); int nbrCommunities = Integer.parseInt(line [0]); // create the array to hold the data double [] [] cData = new double [nbrCommunities] [22]; for (int c = 0; c < nbrCommunities; c++ ) { // Each line contains the data for ONE community. // Reads one line, extracting each comma separated field. String [] oneCommunity = StdIn.readLine().split(regex:","); // Store the data into the array // racial demographics // opens the file to read cData [c] [RD_BLACK] = Double.parseDouble (oneCommunity [RD_BLACK]); cData [c] [RD_NATIVE_AMERICAN] = Double.parseDouble (one Community [RD_NATIVE_AMERICAN] ); cData [c] [RD_ASIAN] = Double.parseDouble (one Community [RD_ASIAN]); = Double.parseDouble (one Community [RD_NATIVE_HAWAIAN]); cData [c] [RD_NATIVE_HAWAIAN] cData [c] [RD_TWO_OR_MORE] cData [c] [RD_WHITE] = Double.parseDouble (oneCommunity [RD_TWO_OR_MORE]); = Double.parseDouble (one Community [RD_WHITE]); = Double.parseDouble (oneCommunity [RD_HISP_OR_LATINO]); = Double.parseDouble (oneCommunity [RD_OTHER]); cData [c] [RD_HISP_OR_LATINO] cData [c] [RD_OTHER] // age cData [c] [AGE_UNDER_10] = Double.parseDouble (oneCommunity [AGE_UNDER_10]); cData [c] [AGE_10_TO_64] = Double.parseDouble (oneCommunity [AGE_10_TO_64]); cData [c] [AGE_OVER_64] = Double. parseDouble (one Community [AGE_OVER_64]); cData [c] [TOTAL_POPULATION] = Double.parseDouble (oneCommunity [TOTAL_POPULATION]); // health = Double.parseDouble (oneCommunity [HLT_PM2_5]); cData [c] [HLT_FLOOD_RISK] = Double.parseDouble (oneCommunity [HLT_FLOOD_RISK]); cData [c] [HLT_FIRE_RIST] = Double.parseDouble (oneCommunity [HLT_FIRE_RIST]); cData [c] [HLT_PM2_5] cData [c] [HLT_ASTHMA] cData [c] [HLT_DIABETES] cData [c] [HLT_HEART_DISEASE] cData [c] [HLT_LIFE_EXPECT] = Double.parseDouble (one Community [HLT_ASTHMA]); = Double.parseDouble (one Community [HLT_DIABETES]); = Double.parseDouble (oneCommunity [HLT_HEART_DISEASE] ); = Double.parseDouble (oneCommunity [HLT_LIFE_EXPECT]); cData [c] [ECON_UNEMPLOYEMENT] = Double.parseDouble (one Community [ECON_UNEMPLOYEMENT] ); cData [c] [ECON_LOW_INCOME] = Double.parseDouble (oneCommunity [ECON_LOW_INCOME]); cData [c] [ECON_DISADVANTAGED] = Double.parseDouble (one Community [ECON_DISADVANTAGED] ); } return cData;
/*
* Variables that hold the column index for a specific data point
* in the data contained in the double [] []
*
* The final keyword implies that the variable cannot be changed.
* The static keyword implies that class-level scope. We'll learn
* non static later in the course.
*
* These variable can be used ANYWHERE in this file.
*/
// Racial Demographics
static final int RD_BLACK
static final int RD_NATIVE AMERICAN
static final int _ASIAN
static final int RD_NATIVE_HAWAIAN
static final int RD_TWO_OR_MORE
static final int RD_WHITE
static final int RD_HISP_OR_LATINO
static final int RD_OTHER
// Age
static final int AGE_UNDER 10
static final int AGE_10_TO_64
static final int AGE_OVER_64
static final int TOTAL POPULATION
// health
static final int HLT_FLOOD_RISK
static final int HLT_FIRE_RIST
static final int HLT_PM2_5
static final int HLT ASTHMA
static final int HLT_DIABETES
= 0;
= 1;
= 2;
= 3;
= 4;
= 5;
= 6;
= 7;
= 8;
= 9;
= 10;
/*
= 11;
= 12;
= 13;
= 14;
= 15;
= 16;
= 17;
static final int HLT_HEART_DISEASE
static final int HLT_LIFE_EXPECT = 18;
// economics
ECON_UNEMPLOYEMENT = 19;
static final int
static final int ECON_LOW_INCOME
= 20;
static final int ECON_DISADVANTAGED = 21;
Transcribed Image Text:/* * Variables that hold the column index for a specific data point * in the data contained in the double [] [] * * The final keyword implies that the variable cannot be changed. * The static keyword implies that class-level scope. We'll learn * non static later in the course. * * These variable can be used ANYWHERE in this file. */ // Racial Demographics static final int RD_BLACK static final int RD_NATIVE AMERICAN static final int _ASIAN static final int RD_NATIVE_HAWAIAN static final int RD_TWO_OR_MORE static final int RD_WHITE static final int RD_HISP_OR_LATINO static final int RD_OTHER // Age static final int AGE_UNDER 10 static final int AGE_10_TO_64 static final int AGE_OVER_64 static final int TOTAL POPULATION // health static final int HLT_FLOOD_RISK static final int HLT_FIRE_RIST static final int HLT_PM2_5 static final int HLT ASTHMA static final int HLT_DIABETES = 0; = 1; = 2; = 3; = 4; = 5; = 6; = 7; = 8; = 9; = 10; /* = 11; = 12; = 13; = 14; = 15; = 16; = 17; static final int HLT_HEART_DISEASE static final int HLT_LIFE_EXPECT = 18; // economics ECON_UNEMPLOYEMENT = 19; static final int static final int ECON_LOW_INCOME = 20; static final int ECON_DISADVANTAGED = 21;
Expert Solution
steps

Step by step

Solved in 8 steps with 5 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,