SA-9, due Oct 25

Assignment

This assignment will give you practice with sets and maps. The program StatesAndCities.java is the skeleton of a program that allows you to add (state, city) pairs to a database of such pairs. They are stored in a Map keyed on state names. The corresponding value is a Set of city names that are within the state. I have replaced method bodies by the comment:

// *** Your Code Here ***.

Your job is to complete the method bodies to make this program work correctly.

Helpful notes

Sample run

A sample run of the finished program is:

Command (q, a, i, P, ?): a Enter state: NH Enter city in the state: Concord Command (q, a, i, P, ?): a Enter state: NH Enter city in the state: Hanover Command (q, a, i, P, ?): a Enter state: MA Enter city in the state: Concord Command (q, a, i, P, ?): a Enter state: MA Enter city in the state: Boston Command (q, a, i, P, ?): a Enter state: VT Enter city in the state: Burlington Command (q, a, i, P, ?): i Enter state: NH Enter city that might be in the state: Concord Concord is in NH Command (q, a, i, P, ?): i Enter state: VT Enter city that might be in the state: Concord Concord is not listed as being in VT Command (q, a, i, P, ?): P MA: Boston Concord NH: Concord Hanover VT: Burlington Command (q, a, i, P, ?): q Bye

Extra Credit

There are many types of elections. In class we looked at instant runoff voting, but there are also regular voting (only first vote on ballot counts; winner is the candidate with the most votes) and approval voting (all candidates on the ballot get a vote; winner is the candidate with the most votes). Modify InstantRunoffOO.java, Ballot.java, Election.java, and VoteTally.java to handle these types of elections as well. After a set of ballots has been read report the winner under each of the three systems.

Blackboard submission

Submit via Blackboard the zip file of a folder containing (1) your StatesAndCities.java, and (2) a screenshot of your test run with convincing test cases (test your code by running the main method of StatesAndCities.java.