-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateCrimeStatsTest.java
More file actions
129 lines (103 loc) · 4.48 KB
/
Copy pathCreateCrimeStatsTest.java
File metadata and controls
129 lines (103 loc) · 4.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package cityCrime;
/**
*
* @author Jonathan T. Fetzer
* class: CS 480, Cal Poly Pomona
* group: Sounds Neat
*
*/
import java.io.IOException;
import com.fasterxml.jackson.databind.ObjectMapper;
public class CreateCrimeStatsTest {
public static void main(String[] args) throws Exception {
boolean JSON = true; // example input: {"city":"Pomona","state":"California"}
CreateCrimeStats cityA = null;
if(JSON){
ObjectMapper mapper = new ObjectMapper();
// replaceAll method prevents mapper.readValue from stripping quotation marks out of JSON format.
CityState cityState = mapper.readValue((args[0].replaceAll("\"", "\\\"")), CityState.class);
try {
cityA = new CreateCrimeStats(cityState.city, cityState.state);
} catch (IOException e) {
e.printStackTrace();
} // end catch
} else { // example input: Pomona California
if(args.length < 2) throw new Exception("must provide city and state as arguments, e.g. Pomona California");
else if(args.length > 2){ // for inputs such as Los Angeles California
int i;
for (i = 1; i < args.length - 1; i++) {
args[0] = args[0] + " " + args[i];
} // end for i
args[1] = args[i];
try {
cityA = new CreateCrimeStats(args[0], args[1]);
} catch (IOException e) {
e.printStackTrace();
} // end catch
} // end else if
} // end else
System.out.println("JSON: " + cityA.crimeStats.toJson()+ "\n");
/*
// print crime data years
System.out.print("Crime data years for " + args[0] + ", " + args[1] + ": ");
CrimeStats.print(cityA.crimeStats.getCrimeDataYears());
System.out.println();
// Print number of murders
System.out.print("Number of murders per year: ");
CrimeStats.print(cityA.crimeStats.getNumMurders());
// Print murder stats
System.out.print("Murders per year per 100,000: ");
CrimeStats.print(cityA.crimeStats.getMurderStats());
System.out.println();
// Print number of rapes
System.out.print("Number of rapes per year: ");
CrimeStats.print(cityA.crimeStats.getNumRapes());
// Print rate stats
System.out.print("Number of rapes per year per 100,000: ");
CrimeStats.print(cityA.crimeStats.getRapeStats());
System.out.println();
// Print number of robberies
System.out.print("Number of robberies per year: ");
CrimeStats.print(cityA.crimeStats.getNumRobberies());
// Print robbery stats
System.out.print("Number of robberies per year per 100,000: ");
CrimeStats.print(cityA.crimeStats.getRobberyStats());
System.out.println();
// Print assault stats
System.out.print("Number of assaults per year: ");
CrimeStats.print(cityA.crimeStats.getNumAssaults());
// Print assault stats
System.out.print("Number of assaults per year per 100,000: ");
CrimeStats.print(cityA.crimeStats.getAssaultStats());
System.out.println();
// Print number of burglaries
System.out.print("Number of burglaries per year: ");
CrimeStats.print(cityA.crimeStats.getNumBurglaries());
// Print burglary stats
System.out.print("Number of burglaries per year per 100,000: ");
CrimeStats.print(cityA.crimeStats.getBurglaryStats());
System.out.println();
// Print number of robberies
System.out.print("Number of thefts per year: ");
CrimeStats.print(cityA.crimeStats.getNumThefts());
// Print theft stats
System.out.print("Number of thefts per year per 100,000: ");
CrimeStats.print(cityA.crimeStats.getTheftStats());
System.out.println();
// Print number of auto thefts
System.out.print("Number of auto thefts per year: ");
CrimeStats.print(cityA.crimeStats.getNumAutoThefts());
// Print Auto Theft stats
System.out.print("Number of auto thefts per year per 100,000: ");
CrimeStats.print(cityA.crimeStats.getAutoTheftStats());
System.out.println();
// Print number of robberies
System.out.print("Number of incidents of arson per year: ");
CrimeStats.print(cityA.crimeStats.getNumArsons());
// Print Auto Theft stats
System.out.print("Number of incidents of arson per year per 100,000: ");
CrimeStats.print(cityA.crimeStats.getArsonStats());
System.out.println();
*/
} // end method main
} // end class