-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathUSStates.java
84 lines (79 loc) · 2.35 KB
/
USStates.java
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
package states;
import java.util.Map;
public class USStates {
/**
* Count states by their first letter.
*
* @return
* A map from the initial (capital) letter to the number of states whose
* names start with that letter. The map should have exactly 26 keys, one
* for each letter of the alphabet. For example, 'A' should be a key with
* value 4 (Alabama, Alaska, Arizona, Arkansas), and 'B' should be a key
* with value 0.
*/
public static Map<Character, Integer> countStatesByFirstLetter() {
// TODO: Write this method.
return null;
}
public static void main(String[] args) {
Map<Character, Integer> counts = countStatesByFirstLetter();
// Do some simple tests. Feel free to add your own.
if (counts.size() != 26) throw new AssertionError();
if (!counts.containsKey('A')) throw new AssertionError();
if (counts.get('A') != 4) throw new AssertionError();
if (!counts.containsKey('B')) throw new AssertionError();
if (counts.get('B') != 0) throw new AssertionError();
}
public static final String[] STATE_NAMES = {
"Alabama",
"Alaska",
"Arizona",
"Arkansas",
"California",
"Colorado",
"Connecticut",
"Delaware",
"Florida",
"Georgia",
"Hawaii",
"Idaho",
"Illinois",
"Indiana",
"Iowa",
"Kansas",
"Kentucky",
"Louisiana",
"Maine",
"Maryland",
"Massachusetts",
"Michigan",
"Minnesota",
"Mississippi",
"Missouri",
"Montana",
"Nebraska",
"Nevada",
"New Hampshire",
"New Jersey",
"New Mexico",
"New York",
"North Carolina",
"North Dakota",
"Ohio",
"Oklahoma",
"Oregon",
"Pennsylvania",
"Rhode Island",
"South Carolina",
"South Dakota",
"Tennessee",
"Texas",
"Utah",
"Vermont",
"Virginia",
"Washington",
"West Virginia",
"Wisconsin",
"Wyoming",
};
}