Question: You will implement a Implementation Overview of Files DO NOT edit ANY class besides StopAndFrisk java For all of these, look at the comments above
You will implement a Implementation
Overview of Files DO NOT edit ANY class besides StopAndFrisk java
For all of these, look at the comments above the methods for more information.
readFile
Remember that you must call readFile every time you test a new CSV file, before calling any other meth
Use the Stdll library to read from a file:
To read one record do: string recordentries stdin. readlinesplit
int year recordEntries;
String description recordEntries String gender recordEntries
String race recordEntries;
String location recordEntries;
Boolean arrested recordEntriesequals Y;
This method outputs the per year. To complete this method:
To complete this method: Create two counters, one for the population frisked and the other for the population arrested. Access the specifi year you are loking for in the database array. Traversethe records in that year updating the counters. Utilize gettris
Create counte black men wh women who Utilize th If If th
Return the resulting array
Note : We are loo male percentage. Note The total
Note : The total percentages should not be above
crimelncrease This method returns a double value representing the percentage of crime increase if the number is positive or crime decrease if the number is negative between any years. The parameters tor thingethod are the descripition of the record year
In the real world context We always want a decrease in crime as the years progress. See if that's the case or not!
Notes:
Make su year. Consider
Consider edge cases: yearl cannot be greater than or equal to year
mostCommonBorough This method outputs the NYC borough where the most amount of stops occurred in a given year. This method will analyze the five following boroughs in New York City: Brooklyn, Manhattan, Bronx, Queens, and Staten Island.
This is my code:
import java.util.ArrayList;
The StopAndFrisk class represents stopandfrisk data, provided by
the New York Police Department NYPD that is used to compare
during when the policy was put in place and after the policy ended.
@author Tanvi Yamarthy
@author Vidushi Jindal
public class StopAndFrisk
The ArrayList keeps track of years that are loaded from CSV data file.
Each SFYear corresponds to year of SFRecords.
Each SFRecord corresponds to one stop and frisk occurrence.
private ArrayList database;
Constructor creates and initializes the @database array
DO NOT update nor remove this constructor
public StopAndFrisk
database new ArrayList;
Getter method for the database.
DO NOT REMOVE nor update this method
public ArrayList getDatabase
return database;
This method reads the records information from an input csv file and populates
the database.
Each stop and frisk record is a line in the input csv file.
Open file utilizing StdIn.setFilecsvFile
While the input still contains lines:
Read a record line see assignment description on how to do this
Create an object of type SFRecord containing the record information
If the record's year has already is present in the database:
Add the SFRecord to the year's records
If the record's year is not present in the database:
Create a new SFYear
Add the SFRecord to the new SFYear
Add the new SFYear to the database ArrayList
@param csvFile
public void readFile String csvFile
DO NOT remove these two lines
StdIn.setFilecsvFile; Opens the file
StdIn.readLine; Reads and discards the header line
WRITE YOUR CODE HERE
String allLines StdIn.readAllLines;
int len allLines.length;
for int i ; i len; i
String recordEntries allLinesisplit;
int year Integer.parseIntrecordEntries;
String description recordEntries;
String gender recordEntries;
String race recordEntries;
String location recordEntries;
Boolean arrested recordEntriesequalsY;
Boolean frisked recordEntriesequalsY;
SFRecord record new SFRecorddescription arrested, frisked, gender, race, location;
boolean targetYearFound false;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
