Skip to Main Content

Introduction to Computer Science

Computer Science Department

Functions – 50 course points

The purpose of this assignment is to practice array manipulation, functions, passing arrays as arguments to functions, and minimal data analysis.

Refer to our Programming Assignments FAQ for instructions on how to install VScode, how to use the command line and how to submit your assignments.

Programming

The assignment has two components:

  1. Coding (47 points) submitted through Autolab.
  2. Reflection (3 points) submitted through a form.
    • Submit the reflection AFTER you have completed the coding component.
    • Be sure to sign in with your RU credentials! (netid@scarletmail.rutgers.edu)
    • You cannot resubmit reflections but you can edit your responses before the deadline by clicking the Google Form link, signing in with their netid, and selecting “Edit your response”

We provide a zip file in Autolab containing Communities.java and input files.

Observe the following rules:

  1. DO NOT add any import statements
  2. DO NOT add the project statement
  3. DO NOT change the class name
  4. DO NOT change the headers of ANY of the given methods
  5. DO NOT add any new class fields
  6. DO NOT use System.exit()
  7. ONLY print the result as specified by each problem. Observe the examples’ output, display only what the problem is asking for.
    1. DO NOT print other messages, follow the examples for each problem.

Climate and Economic Justice

Welcome to the Climate and Economic Justice assignment!

In this assignment, you’ll be working with community data from various regions to explore the intersection of climate and economic justice. The provided data includes information about racial demographics, pollution levels, flood risks, poverty rates, and more. Your goal is to process this data using arrays and analyze the social and environmental aspects of different communities.

  • Communities data analysis is an important tool to understand communities aspects. For example, flood risk and high PM2.5 levels to name a few.
  • The data can help understand which communities are susceptible to flooding, or if disadvantaged communities are more susceptible to flooding than non-disadvantage communities.
The data used in this assignment was obtained from the Geoplatform screening tool. The data file provided  contains only a portion of the original data set.
 

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

Before submission

Collaboration policy. Read our collaboration policy here.

Submitting the assignment. Submit Communities.java via the web submission system called Autolab. To do this, click the Assignments link from the course website; click the Submit link for that assignment.

Getting help

If anything is unclear, don’t hesitate to drop by office hours or post a question on Piazza.

  • Find instructors office hours here
  • Find tutors office hours in Canvas -> Tutoring, RU CATS
  • Find head TAs office hours here
  • POST on Piazza in Canvas -> Piazza
  • In addition to office hours we have the CAVE (Collaborative Academic Versatile Environment), a community space staffed with lab assistants which are undergraduate students further along the CS major to answer questions.

Assignment by Navya Sharma and Nicole Le