Question

Write a program called EventManager, that allows a user to search for 9-1-1 incidents recorded in Seattle The data is given tWhat should your program do? Read file Seattle_911_Incidents.csv from the file path passed to your program as a 1. command- lNumber of events in district X: nnn If the user types something other than -t type or -d district, you should print that the

Write a program called EventManager, that allows a user to search for 9-1-1 incidents recorded in Seattle The data is given to you in file Seattle_911_Incidents.csv which contains 500 records (a subset of the approximately 53,000 911 calls made in Seattle in the years 2015-2017). This dataset is the Police responses to 9-1-1 calls within the city during the 2015-2017 years. You can get the full data set from http://data.seattle.gov. The data consists of 500 rows, where each row is an event. Each event has the following data: ID: The event ID 2. Type: The event type (e.g., THEFT, DISTURBANCES, etc.) Clearance Date: The date and time Location: The address where the event took place. 5. District/Sector: The district/sector code. 6. Zone/Beat: The zone/beat code. 1. 3. 4. Seattle is divided into five geographic areas. Within those areas are the 5 precincts or police stations: North, East, South, West and Southwest. Precinct boundaries were determined through consideration of neighborhood boundaries, geographic and other natural boundaries. Each precinct contains smaller geographic areas called sectors. There are 17 sectors in the city. Each of these sectors is divided into between 3 smaller sections called Zone/Beats. These are the areas that individual patrol officers are assigned responsibility for. See the figures below.
What should your program do? Read file Seattle_911_Incidents.csv from the file path passed to your program as a 1. command- line argument. That is, I will execute you program in a way like this: java EventManager C:\Temp\Seattle_911_Incidents.csv So args[0] in your main method will have the full path of file Seattle_911_Incidents.csv. You need this path to be able to open and read the file content 2. Continuously instruct the user with the following sentence until the user enters q: Search by event type (-t type) or district (-d code) (or q to quit): 3. If the user enters q, then print "Thank you for using our search program" and stop. Otherwise, determine what the user typed (-t followed by a type, or -d followed by a district 4. code) Search the data and output the number of events like this: 5. Number of events having type X: nnn or
Number of events in district X: nnn If the user types something other than -t type or -d district, you should print that the entry is 6. invalid: Invalid entry: expecting -t type or-d code In this case you should not end the program. Continue asking the user as indicated in step 1 Here is an example output (NOTE that the output numbers circled in blue are not correct here. This is just a dummy example. Its purpose is to just show you the output format and what to check for):
0 0
Add a comment Improve this question Transcribed image text
Answer #1

I have taken Seattle_Real_Time_Fire_911_Calls.csv file which contains 1.37M rows. The second column is Type and eighth column is (Seattle Police Department Micro Community Policing Plan Areas). I have used eighth column as district code because there is not district code in data sample I have taken. (change the index values according to your csv file)

Code :

package controller;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;

public class EventHandler {

   public static void main(String[] args) throws IOException {
       // TODO Auto-generated method stub
       int count=0;
       Scanner sc = new Scanner(System.in);
       while(true){
           // Read file from command line argument variable
           FileReader fr = new FileReader(args[0]);
           BufferedReader br = new BufferedReader(fr);
           System.out.println("Search By Event Type (-t type) or District (-d district) or q to quit");
           String input = sc.nextLine();
           // Check for search
           // if starts with -t
           if(input.startsWith("-t")){
               // Extract the type to search
               String type = input.substring(3);
               System.out.println(type);
               String line;
               br.readLine();
               while ( (line = br.readLine()) != null ) {
                   String[] values = line.split(",");
                   try{
                       // Type at second column so values[1]
                       if(values[1].equals(type)){
                           count++;
                       }}catch(ArrayIndexOutOfBoundsException e){

                       }
               }
               System.out.println(count);
               count=0;
           }
           // If starts with -d
           else if(input.startsWith("-d")){
               String district = input.substring(3);
               System.out.println(district);
               String line;
               br.readLine();
               while ( (line = br.readLine()) != null ) {
                   String[] values = line.split(",");
                   try{
                       if(values[7].equals(district)){
                           count++;
                       }}catch(ArrayIndexOutOfBoundsException e){
                       }
               }
               System.out.println(count);
               count=0;          
           }else if(input.equals("q")){
               break;
           }else{
               System.out.println("Please Enter Correct Input");
           }
           br.close();
       }
       sc.close();
   }
}

Output:

Search By Event Type (-t type) or District (-d district) or q to quit
-t Aid Response
Aid Response
662502
Search By Event Type (-t type) or District (-d district) or q to quit
-d 14
14
119462
Search By Event Type (-t type) or District (-d district) or q to quit
-u
Please Enter Correct Input
Search By Event Type (-t type) or District (-d district) or q to quit
q

Add a comment
Know the answer?
Add Answer to:
Write a program called EventManager, that allows a user to search for 9-1-1 incidents recorded in Seattle The data is g...
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
  • Write a menu based program implementing the following functions: (0) Write a function called displayMenu that...

    Write a menu based program implementing the following functions: (0) Write a function called displayMenu that does not take any parameters, but returns an integer representing your user's menu choice. Your program's main function should only comprise of the following: a do/while loop with the displayMenu function call inside the loop body switch/case, or if/else if/ ... for handling the calls of the functions based on the menu choice selected in displayMenu. the do/while loop should always continue as long...

  • Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a funct...

    Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in...

  • 1. Write a program called Numbers that a. prompts the user for a file name. b....

    1. Write a program called Numbers that a. prompts the user for a file name. b. reads that file assuming that its contents consist entirely of integers. c. prints the maximum, minimum, sum, count (number of integers in the file), and average of the numbers. For example, if the file numberinput.dat has the following content: 4 -2 18 15 31 27 Your program should produce the following output: csc% java Numbers Enter file name: numberinput.daft Maximum31 Minimum- -2 Sum -...

  • Write a C++ program that prompts the user with the following menu options: Erase-ArrayContent Count-Words Quit...

    Write a C++ program that prompts the user with the following menu options: Erase-ArrayContent Count-Words Quit 1. For Erase-ArrayContent option, write complete code for the C++ function Erase described below. The prototype for Erase function is as follow: void Erase( int a[ ], int * N, int * Search-Element) The function Erase should remove all occurrences of Search-Element from the array al). Note that array a[ ] is loaded with integer numbers entered by the user through the keyboard. N...

  • DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to...

    DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to add new phone contacts, display a list of all contacts, search for a specific contact by name, delete a specific contact. The program should provide the user with a console or command line choice menu about possible actions that they can perform. The choices should be the following: 1. Display list of all contacts. 2. Add a new contact. 3. Search for a contact...

  • Task 1: Write a Python program that takes as input from the user the name of a file containing po...

    python code: Task 1: Write a Python program that takes as input from the user the name of a file containing postcode/location information. Each line in the file consists of the postcode followed by a tab followed by a comma-separated list of locations that have that postcode. For example, the file Small.txt contains: 3015 Newport,South Kingsville,Spotswood 3016 Williamstown 3018 Altona,Seaholme 3019 3021 Albanvale,Kealba,Kings Park,St Albans Braybrook, Robinson Your program should create a list of postcode/location pairs with each pair stored...

  • Write a C++ menu driven Payroll program. Must be user friendly.   Menu 1. Check data file  ...

    Write a C++ menu driven Payroll program. Must be user friendly.   Menu 1. Check data file   2. Read Data file 3. Process payroll for one employee 4. Process payroll for all employees 5. Print out to a text or an HTML file 6. Exit You must use the following Payroll classes, structures, pointers, arrays, enum, vector, recursive, advance file I/O, STL, iterators and containers. The program to process an input file below to calculate tax of 28% and output it...

  • Use C++ For this week’s lab you will write a program to read a data file...

    Use C++ For this week’s lab you will write a program to read a data file containing numerical values, one per line. The program should compute average of the numbers and also find the smallest and the largest value in the file. You may assume that the data file will have EXACTLY 100 integer values in it. Process all the values out of the data file. Show the average, smallest, largest, and the name of the data file in the...

  • User Profiles Write a program that reads in a series of customer information -- including name,...

    User Profiles Write a program that reads in a series of customer information -- including name, gender, phone, email and password -- from a file and stores the information in an ArrayList of User objects. Once the information has been stored, the program should welcome a user and prompt him or her for an email and password The program should then use a linearSearch method to determine whether the user whose name and password entered match those of any of...

  • Write a c++ program in that file to perform a “Search and Replace All” operation. This...

    Write a c++ program in that file to perform a “Search and Replace All” operation. This operation consists of performing a case-sensitive search for all occurrences of an arbitrary sequence of characters within a file and substituting another arbitrary sequence in place of them. Please note: One of the biggest problems some students have with this exercise occurs simply because they don’t read the command line information in the course document titled “Using the Compiler’s IDE”. Your program: 1. must...

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