When turning in a homework problem, mark it with the exercise number shown in bold here. These will be the reference numbers I use in reporting back your standing on the homework.
9.4.x1:
Write a function using MySQL, named county_name
, which is passed a county ID as a parameter and returns the county's name as its result value. Your function should use the sos.counties
table. You can ignore the possibility that an invalid ID might be provided. If done correctly, the following query should produce a table of 38 rows, a few of which are shown after the query:
select precinct_name, county_name(county_id) from sos.precincts where legislative_district = '19A' + ------------------ + --------------------------- + | precinct_name | county_name(county_id) | + ------------------ + --------------------------- + | LIME TWP | Blue Earth | . . . | ST PETER W-2 P-1 | Nicollet | | ST PETER W-2 P-2 | Nicollet | | TRAVERSE TOWNSHIP | Nicollet | | WEST NEWTON TOWNSHIP | Nicollet | + ------------------ + --------------------------- +
9.6.x1: Do either the Python or the Java version of this problem, as given below.
Python version: These instructions should work on the MCS Department's lab machines. If you are using your own computer, you will need to be on the Gustavus network and to have installed MySQL Connector/Python.
Run the attached ListParties Python program. As the program stands, it shouldn't produce any output but also shouldn't produce any error messages. The reason to run it without making any changes is to make sure you've got the mechanics of connecting to the database server working.
Start by extending the program to print one line per candidate for a U.S. office, showing the office title and party abbreviation retrieved from the sos.candidates
table. Once that works, modify the program to produce output as shown here:
U.S. Representative District 1: DFL, R U.S. Representative District 2: DFL, IP, R U.S. Representative District 3: DFL, R U.S. Representative District 4: DFL, IP, R U.S. Representative District 5: DFL, IP, R U.S. Representative District 6: DFL, IP, R U.S. Representative District 7: DFL, R U.S. Representative District 8: DFL, GP, R U.S. Senator: DFL, IP, LIB, R
Java version: These instructions should work on the MCS Department's lab machines. If you are using your own computer, you will need to be on the Gustavus network and to have installed MySQL Connector/J.
Compile and run the attached ListParties JDBC program. You will need to put the MySQL driver in the list of places that Java looks for classes. If you are working in a Terminal window, you can set the CLASSPATH
environment variable using a command like this:
export CLASSPATH=/Users/Shared/mysql-connector-java-5.1.34-bin.jar:.
If you are working in Eclipse, use the instructions linked here.
As the program stands, it shouldn't produce any output but also shouldn't produce any error messages. The reason to run it without making any changes is to make sure you've got the mechanics of connecting to the database server working.
Start by extending the program to print one line per candidate for a U.S. office, showing the office title and party abbreviation retrieved from the sos.candidates
table. Once that works, modify the program to produce output as shown here:
U.S. Representative District 1: DFL, R U.S. Representative District 2: DFL, IP, R U.S. Representative District 3: DFL, R U.S. Representative District 4: DFL, IP, R U.S. Representative District 5: DFL, IP, R U.S. Representative District 6: DFL, IP, R U.S. Representative District 7: DFL, R U.S. Representative District 8: DFL, GP, R U.S. Senator: DFL, IP, LIB, R
Instructor: Max Hailperin