In: Computer Science
To run an effective political campaign, it’s important to plan well and use resources efficiently. Don’t waste time and money on those who probably won’t vote, will probably vote for you, or will probably vote against you. Focus on those who are likely to vote and who are currently undecided. Start by using electronically available historical voting information to assign each potential voter to one of four “pools”:
Gather money and support from pool 1. Then, use telephone polling to qualify individual voters as “yes,” “no,” or “maybe,” and focus money and labor on “maybe” voters in pool 2.
Use the following named constants (named constants are described in §3.14):
REGULAR_TURNOUT_FRACTION = 0.833
DOLLARS_PER_SOLICITATION = 5.00
CLERICAL_HOURS_PER_CALL = 0.05
TELEPHONE_HOURS_PER_CALL = 0.1
TRANSPORT_HOURS_PER_CALL = 0.05
OVERHEAD_FRACTION = 0.25
After gathering historical data and estimating the fraction of votes in different pools, compute
otherTurnoutFraction ←
(probableVoters – REGULAR_TURNOUT_FRACTION *
(ourPartyRegulars + independentRegulars)) /
(totalRegistered – (ourPartyRegulars + independentRegulars))
Then, output expected numbers of votes from each pool to clarify the situation. After documenting expected funding, decide on allocation of worker labor among the four pools. Input integers zero or one only, multiply these inputs by respective pool size, and accumulate to generate a total number of “calls”. Then, use the predefined constants to determine the total number of labor hours required in each type of work. Assume the time for each solicitation call is twice that for other calls, each poll watcher spends 10 hours, and the overhead time is the multiplier times the sum of all other times. (Decisions about how to use the money raised are not included. The poll watcher and substantial clerical times are devoted to progressively shortening voter lists as polling identifies individuals who want to vote but haven’t decided which way or need transportation to the voting place.)
Write a Java program to help organize estimates of votes, money, and labor. Use named constants for historical data and estimated fraction of votes in different voting pools. More specifically, use named constants for the first 10 numeric values shown below. The six lines under Expected Votes are calculated values. Use two more named constants for the first two numeric values under Expected Funding. The third value under Expected Funding is calculated. Use four more named constants for the four numeric values under Work Plan. The first six of the last eight lines are calculated results. The next to last line displays a final named constant, and the last line is a result calculated from it.
Sample session:
POLITICAL CAMPAIGN PLANNER
Assumed total number of registered voters: 5000
Assumed registered voters in our party: 1500
Assumed registered independent voters: 2000
Assumed number of regular voters in our party
(voting probability = 0.833): 900
Assumed number of regular independent voters
(voting probability = 0.833): 1000
Assumed average number of actual voters: 2000
Assumed expected fraction of our party regular votes: 1.0
Assumed expected fraction of independent regular votes: 0.5
Assumed expected fraction of our party occasional votes: 0.6
Assumed expected fraction of other votes: 0.1
Expected votes:
First pool: regular party votes = 749
Second pool: regular independent votes = 416
Third pool: occasional party votes = 48
Last pool: other votes = 33
total expected votes = 1246
votes needed = 1001
Expected Funding:
Assumed number of early $500 donors: 4
Assumed number of solicitation calls: 50
Amount available for campaign = 2250.0
Work Plan:
Call first pool assumption [yes:1, no:0]: 1
Call second pool assumption [yes:1, no:0]: 1
Call third pool assumption [yes:1, no:0]: 0
Assumed number of polling places: 2
Clerical hours = 95.0
Telephone hours = 200.0
Poll watcher hours = 20.0
Transport hours = 95.0
Overhead hours = 102.5
Total worker hours = 512.5
Enter number of workers available: 25
Hours per worker = 20
Modify the program of part A to make it accept inputs that override the initialized values. Make your program so that what appears on your computer screen matches the following sample session. As always, if a sample session contains italicized values, those values indicate user input.
Sample session:
POLITICAL CAMPAIGN PLANNER
Working code implemented in Perl and appropriate comments provided for better understanding.
main.pl Source Code:
use strict;
use warnings;
use diagnostics;
#global (every year) vars
my $regular_turnout_fraction = 0.833;
my $dollars_per_solicitation = 5;
my $overhead_fraction = .25;
#these vars are per call
my $clerical_hours = .05;
my $telephone_hours = .1;
my $transport_hours = .05;
#vars from previous election
print "Enter total registered voters: ";
my $registered_voters = <>;
chomp $registered_voters;
print "Enter number registered party voters: ";
my $registered_party = <>;
chomp $registered_party;
print "Enter registered independent voters: ";
my $registered_independent = <>;
chomp $registered_independent;
print "Enter number of regular voters in our party: ";
my $regular_party = <>;
chomp $regular_party;
print "Enter number of regular independent voters: ";
my $regular_independent = <>;
chomp $regular_independent;
print "Enter total number of actual voters: ";
my $actual_voters = <>;
chomp $actual_voters;
#expected fraction of votes
print "Enter expected fraction of our party regular votes: ";
my $expected_regular = <>;
chomp $expected_regular;
print "Enter expected fraction of independent regular votes:
";
my $expected_independent = <>;
chomp $expected_independent;
print "Enter expected fraction of our party occasional votes:
";
my $expected_occasional = <>;
chomp $expected_occasional;
print "Enter expected fraction of other votes: ";
my $expected_other = <>;
chomp $expected_other;
#expected votes
my $other_fraction = (
($actual_voters - ($regular_turnout_fraction * ($regular_party +
$regular_independent)))
/
($registered_voters - ($regular_party +
$regular_independent))
);
my $occasional_party = ($registered_party - $regular_party);
my $voting_party = int($regular_party * $regular_turnout_fraction *
$expected_regular);
my $voting_independent = int($regular_independent *
$regular_turnout_fraction * $expected_independent);
my $voting_occasional_party = int($occasional_party *
$other_fraction * $expected_occasional);
my $registered_others = ($registered_voters - $registered_party -
$regular_independent);
my $voting_others = int($registered_others * $other_fraction *
$expected_other);
print "Pool 1. regular party votes = $voting_party\n";
print "Pool 2. regular independent votes =
$voting_independent\n";
print "Pool 3. occasional party votes =
$voting_occasional_party\n";
print "Pool 4. other votes = $voting_others\n";
my $expected_votes = ($voting_party + $voting_independent +
$voting_occasional_party + $voting_others);
print "Total expected votes = $expected_votes\n\n";
my $needed_votes = (($actual_voters / 2) + 1);
print "Votes needed to win = $needed_votes\n\n";
#expected funding
print "Expected Funding\n";
print q(Enter number of early $500 donors: );
my $donors_early = (<> * 500);
chomp $donors_early;
print "Enter number of solicitation calls: ";
my $solicitation_calls = <>;
chomp $solicitation_calls;
#amount raised
my $raised = $donors_early + ($solicitation_calls *
$dollars_per_solicitation);
print "Amount available for campaign = $raised\n\n";
#work plan
#the pool calls need to represent the amount in each pool
print "Call Pool 1? [yes:1, no:0]: ";
my $call_pool_1 = (<> * $regular_party);
chomp $call_pool_1;
print "Call Pool 2? [yes:1, no:0]: ";
my $call_pool_2 = (<> * $regular_independent);
chomp $call_pool_2;
print "Call Pool 3? [yes:1, no:0]: ";
my $call_pool_3 = (<> * $occasional_party);
chomp $call_pool_3;
print "Enter number of polling places: ";
my $polling_places = <>;
chomp $polling_places;
#work hours
my $pool_calls = ($call_pool_1 + $call_pool_2 +
$call_pool_3);
my $clerics_total = ($pool_calls * $clerical_hours);
my $telephone_total = (($solicitation_calls * (2 *
$telephone_hours)) + ($pool_calls * $telephone_hours));
my $poll_watchers = (10 * $polling_places);
my $transport_totals = ($pool_calls * $transport_hours);
my $overhead = ($overhead_fraction * ($clerics_total +
$telephone_total + $poll_watchers + $transport_totals));
my $total_hours = ($overhead + $transport_totals + $poll_watchers +
$telephone_total + $clerics_total);
print "Clerical hours = $clerics_total\n";
print "Telephone hours = $telephone_total\n";
print "Poll watcher hours = $poll_watchers\n";
print "Transport hours = $transport_totals\n";
print "Overhead hours = $overhead\n";
print "Total worker hours = $total_hours\n\n";
print "Enter number of workers available: ";
my $workers = <>;
chomp $workers;
my $workers_hours_per = ($total_hours / $workers);
print "Hours per worker = $workers_hours_per\n";
Code Screenshots:
Sample Output Screenshots: