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
Write a program called EventManager, that allows a user to search for 9-1-1 incidents recorded in Seattle The data is g...
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 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. 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 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 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...
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 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 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, 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 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...