CS& 141, Spring 2022 Programming Project # 5: Gerrymandering (20 points) Due: Friday, May 20, 2022, 11:59 PM Thanks to a

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

CS& 141, Spring 2022 Programming Project # 5: Gerrymandering (20 points) Due: Friday, May 20, 2022, 11:59 PM Thanks to a

Post by answerhappygod »

Cs 141 Spring 2022 Programming Project 5 Gerrymandering 20 Points Due Friday May 20 2022 11 59 Pm Thanks To A 1
Cs 141 Spring 2022 Programming Project 5 Gerrymandering 20 Points Due Friday May 20 2022 11 59 Pm Thanks To A 1 (244.82 KiB) Viewed 15 times
Cs 141 Spring 2022 Programming Project 5 Gerrymandering 20 Points Due Friday May 20 2022 11 59 Pm Thanks To A 2
Cs 141 Spring 2022 Programming Project 5 Gerrymandering 20 Points Due Friday May 20 2022 11 59 Pm Thanks To A 2 (221.75 KiB) Viewed 15 times
Cs 141 Spring 2022 Programming Project 5 Gerrymandering 20 Points Due Friday May 20 2022 11 59 Pm Thanks To A 3
Cs 141 Spring 2022 Programming Project 5 Gerrymandering 20 Points Due Friday May 20 2022 11 59 Pm Thanks To A 3 (245.06 KiB) Viewed 15 times
Required files:
district.txt
eligible voters
CS& 141, Spring 2022 Programming Project # 5: Gerrymandering (20 points) Due: Friday, May 20, 2022, 11:59 PM Thanks to and to Marty Stepp and Stuart Reges for parts of this document. This assignment focuses on reading input files. Turn in a file named Gerrymandering.java. You will need DrawingPanel.java, which you used on previous assignments, to write this program. Program Description: Recently gerrymandering has been a popular topic in the news and the subject of several Supreme Court cases. Gerrymandering is creating voting districts in such a way that gives one party an unfair advantage over the other. Political parties do this to try to help themselves stay in power. Recently, a research group came up with a math- ematical definition for what constitutes gerrymandering. For this project, you will prompt the user for a state name, and then determine whether the state's districts are gerrymandered, according the researchers' definition, and output a graphical representation of the districts on a Drawing Panel. The input data about states' districts and total voters comes from two input files provided on the course web site. Even if you disagree with this definition of gerrymandering, it is interesting to understand it better as the courts debated it. Your program should give an introduction and then prompt the user for a state name. It should then read the district file searching for that state, case-insensitively (that is, you should find the state regardless of the capitali- zation the user uses when typing it in). If the state is found in the file, your program should print the total wasted votes of democrats, the total wasted votes of republicans, the total voters in the state, who has gained an advantage from gerrymandering the state if it is gerrymandered, and display information about the state graphically. This program allows you to search through data about congresssional voting districts and determine whether a particular state is gerrymandered. Drawing Panel Eile View Help Arizona 4738332 elgible volers Enter state names without spaces. For instance, enter New Mexico as NewMexico. Which state do you want to look up? Arizona Total Wasted Democratic votes: 327852 Total Wasted Republican votes: 369697 Gerrymandered benefiting the Democrats 4738332 eligible voters Input Data and Files: Your program reads data from two files. Download them from our web site to the same folder as your program. 1. districts.txt: congressional district date Each line of districts.txt contains a state name followed by district information in groups of three. The first of the three is the district name, the second the democratic votes in that district and the third the republican votes in that district. De- pending on the size of the state, there will be a different num- €20,0) ber of districts. For example: Arkansas 1 63555 124139 2 103477 123073 3 0 151630 4 87742 110789 Alaska 1 114596 142566 Rhode Island 1 87060 58877 2 105716 63844 Notice that state names that are normally multiple words have the spaces between words removed, as with Rhode Island in the example above. Districts will always be integers starting at 1 for the first district and increasing by one for each succeeding district. The vote counts will always be integers. 1 of 3

Once the user types a state name (you may assume they do not include spaces), search each line of districts.txt to see if it contains data for that state. If the state name is found, output its data line to the console, then construct a DrawingPanel to graph the data (see next page). Your code should not assume that the file is sorted alpha- betically. If the state name is not found, output a "not found" message and don't show any data. No Drawing Panel should appear. This program allows you to search through data about congresssional voting districts and determine whether a particular state is gerrymandered. Enter state names without spaces. For instance, enter New Mexico as NewMexico. Which state do you want to look up? mErLin "mErLin" not found. The data displayed above has a different number of districts for each state. Your program should work properly with any number of districts of data greater than 0. Since there is a limit to the size of the Drawing Panel, you may not be able to see all districts worth of data at the default height, but your code should process as many districts of data as it finds in the line. 2. eligibleVoters.txt: the number of eligible voters in each state If the state name is found in districts.txt, you should also read eligiblevoters.txt to find its total number of eligible voters. The number of eligible voters should be printed to the console and also drawn on the Draw- ingPanel. Every state name in districts.txt is also in eligibleVoters.txt, so you do not need to worry about a state having district data but no eligible voter data. Each line of eligibleVoters.txt contains a state name, followed by the eligible voter count for that state. For example: Alabama 3606103 Alaska 519501 Arizona 4738332 Arkansas 2148441 California 25278803 Though the two input files contain different data, the task of searching for a state name in districts.txt is very similar to the task of searching for a state name in eligibleVoters.txt. Your code should take advantage of this fact and should avoid redundancy. You should write your code in such a way that you stop searching a file once you find a line that has the name you're searching for. You may not assume the input files will have 50 lines. Your program must work on any length input file. Graphical Output: The panel's overall size is 500x500 pixels. Its background is white. It has a black line drawn horizontally 20 pixels from the top and a black line drawn vertically in the middle of the panel from top to bottom. The state name is drawn at (0, 15). The eligible voters data is drawn at a y of 15 and 140 pixels from the right hand edge of the panel. Each district is represented by a horizontal bar that stretches across the entire width of the panel. These bars are 20 pixels tall each. The first one starts 25 pixels from the top of the panel. There are 5 empty pixels between each bar. The blue part of the bar represents the total democratic votes in the district. The red represents the total republican votes in a district. The total votes for each party in each district are in the districts.txt file. The width of the democratic portion should be: democratic-votes/ (democratic-votes + republican-votes) width-of-the-panel. 2 of 3

Determining Gerrymandering: You can determine gerrymandering by counting up and comparing the wasted votes cast for each party. We will define a wasted vote as any vote not needed to win the election. That means all votes for the party that loses the district seat are wasted as well as all votes for the winning party other than the half + 1 they need to win the majority. For example, imagine that there was a state with the following districts: Dem GOP Wasted Dem Wasted GOP District 1: 2 7 2 2 District 2: 4 5 4 0 District 3: 10 7 1 7 Total: 16 19 7 9 Having calculated this data, we can sum up the wasted votes for each district. We find that the democrats wasted 7 votes and the republicans wasted 9. It is impossible to make voting districts exactly fair and so we shouldn't expect the wasted vote counts to be equal. However, researchers have discovered that it is almost impossible for the disadvantaged party to recover if the difference in wasted votes is greater or equal to 7%. Therefore, the researchers, as well as us for the purposes of this assignment, will consider a state gerrymandered when there is a 7% or greater difference in the wasted votes. Use the following formula to calculate the percentage difference: (wasted-dem-votes - wasted-rep-votes) / ((wasted-dem-votes + wasted-rep-votes)/2)* 100 Implementation Guidelines: We suggest you begin with the text output and file processing, then any "fixed" graphical output, and then the bars. Your program should work correctly regardless of the capitalization the user uses to type the state name. If the user types "AlAbAMA" or "alabama", you should find it even though the input files have it as "Alabama". Detailed Implementation Steps: 1. Get your program to open districts.txt, read through it and print out all of the lines. 2. Alter your program to only output the line that contains the data for Washington. 3. Add code to read in a state name from the user and convert your line search to find a line that matches the user typed in state instead of always matching "Washington". 4. Alter your program to work with any capitalization of the state name. 5. Add a message that tells a user a line couldn't be found if they type in something that isn't a state name. 6. Add code to search through eligibleVoters.txt and find the correct line. 7. Add a Drawing Panel and draw the two black lines, state name and eligible voter strings on it. 8. Write code to go through the line of data for the state and add up the total wasted votes for each party. 9. Write code to calculate whether the state is gerrymandered. 10. Output the blue and red bars on the DrawingPanel. Stylistic Guidelines: You should have at least these two constants. If the constant values are changed, your output should adapt. • The width of the Drawing Panel, as an integer (default of 500) c.g. If you change the width to 600, each bar should still be the width of the screen. • The height of the DrawingPanel, as an integer (default of 500) We will be especially picky about redundancy. For full credit, your methods should obey these constraints: • The main function should not draw on a DrawingPanel, nor read lines of input from a file. • You may not calculate whether a state is gerrymandered in the same function that draws on the DrawingPanel, or reads from the file. Your functions should be well-structured and avoid redundancy, and your main function should be a concise summary of the overall program. Avoid "chaining," which is when many functions call each other without ever returning to main. For this assignment you are limited to the language features in lectures 1-11. Follow past stylistic guidelines about inden- tation, line lengths, identifier names, and localizing variables, and commenting at the beginning of your program, at the start of each method, and on complex sections of code. You may not have any non-constant global variables. 3 of 3
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply