Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

part of nums.txt 2, 6, 42789 2, 5, 73106 1, 3, 26828 1, 6, 86356 1, 4, 82325 2, 5, 48116 2, 4, 17988 2,

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedpart of nums.txt

2, 6, 42789 2, 5, 73106 1, 3, 26828 1, 6, 86356 1, 4, 82325 2, 5, 48116 2, 4, 17988 2, 6, 58931 1, 6, 15315 2, 6, 73844 1, 3, 21326 1, 4, 33165 2, 5, 72274 2, 5, 65527 2, 5, 42249 2, 6, 25722 2, 6, 96433 1, 3, 93663 1, 7, 61046 2, 3, 50041 1, 4, 49526 1, 6, 79890 1, 6, 46645 1, 6, 14032 1, 4, 93557

For Project \#1, you will write a program to determine who has won a recall election! Our program is modeled on the Governor Gavin Newsom recall election of 2021, but you can use fictional candidates instead if you prefer. For this assignment, you should write the following 5 parts: Candidate - An enum with 4 candidates of your choice, plus a 5th option, NONE Vote - 3 instance variables: a boolean recall (where true means "yes, recall"), a Candidate candidate, and int voterID - A 3-argument constructor - Getters for all 3 instance variables - A tostring () that identifies the Vote by voterid and says either "yes" or "no" to the recall, and which candidate they voted for. For example, "Vote 56789 voted yes on the recall and voted for PIKACHU." - You should also copy and insert this equals method directly into your Vote class (when we get to inheritance and polymorphism in class, we'll explain why this is necessary): public boolean equals(Object other ){ boolean same = false; if (other != null \& \& other instanceof Vote ){ same = voterID ==((( Vote) other ) getVoterID ()); return same; Tally. - 2 instance variables: an int votes and a Candidate candidate - A 2-argument constructor - Getters for both instance variables - A tostring () that prints something like "Candidate PIKACHU has 450 votes" VoteList - 2 instance variables: an int count and an ArrayList vlist - a no-argument constructor that sets count to 0 and initializes vlist to an empty ArrayList - addVote (Vote vote), which should add a vote to vlist - but only if vlist doesn't already contain that vote. If the vote is successfully added, count should be incremented and the method should print the tostring () of the vote plus "successfully added". If the vote is not successfully added (because it would be a duplicate), the method should print a message like "Vote 56789 is a duplicate" (in other words, using the voterID of the vote). - printList (), which should print all the Votes in the vlist. - numYesRecall (), which returns an int which is the number of votes that agreed to the recall. - numNoRecall (), which returns an int which is the number of votes against the recall. - isgavinRecalled (), or insert your fictional governor's name instead, which should return a String summary of whether the governor is recalled or not, and says the total number of votes for and against. - tallyCandidates (), which should return an ArrayList. This method should iterate through vlist to count up how many votes went to each candidate. It should also create a Tally object for each candidate, and add each Tally object to a brand new ArrayList. Return this ArrayList. - printCandidatetally (), which should return a String. This method should iterate through the ArrayList that comes from tallyCandidates (), and for each Tally, it should concatenate the tostring () 's, and return the overall String. - getWinningCandidate (), which should return a Candidate. This method should iterate through the ArrayList that comes from tallyCandidates (), and should find the Candidate with the highest votes. That Candidate should be returned. Your Driver class should contain a ma in method but no instance variables or methods. In this ma in method, you should use Scanner to read in this file , nums.txt. Each line should be turned into a Vote, and then added to a VoteList object. Let's see how you should parse each line of your nums. txt file: After turning each line of nums . txt into a Vote object that is added to VoteList, the program should conclude with the following three statements (but note that your isGavinRecalled() method may be differently named, and you might not have called your VoteList object "listvotes"): System.out.println("Will Gavin Newsom be recalled? " + listvotes.isGavinRecalled()); System.out.println("How many votes for each candidate?" + listvotes.printCandidateTally()); System.out.println("Which replacement candidate won the most votes?" + listvotes.getWinningCandidate()); Voter \#83479 voted yes on recalling Gavin Newsom and voted for LARRY_ELDER. Successfully added! Voter \#49049 voted no on recalling Gavin Newsom and voted for NONE. Successfully added! Voter \#41355 voted yes on recalling Gavin Newsom and voted for LARRY_ELDER. Successfully added! Voter \#41387 voted yes on recalling Gavin Newsom and voted for LARRY_ELDER. Successfully added! Voter \#86609 voted yes on recalling Gavin Newsom and voted for JOHN_COX. Successfully added! Voter \#74317 voted yes on recalling Gavin Newsom and voted for LARRY_ELDER. Successfully added! Voter \#77992 voted no on recalling Gavin Newsom and voted for LARRY_ELDER. Successfully added! Voter \#58284 voted yes on recalling Gavin Newsom and voted for JOHN_COX. Successfully added! Voter \#68623 voted yes on recalling Gavin Newsom and voted for KEVIN_FAULCONER. Successfully added. Voter \#15265 voted yes on recalling Gavin Newsom and voted for KEVIN_FAULCONER. Successfully added. Voter \#86414 voted yes on recalling Gavin Newsom and voted for LARRY_ELDER. Successfully added! Voter \#35435 voted no on recalling Gavin Newsom and voted for LARRY_ELDER. Successfully added! Voter \#86229 voted yes on recalling Gavin Newsom and voted for NONE. Successfully added! Will Gavin Newsom be recalled? No. 501 votes against recall, 497 votes in favor. How many votes for each candidate? Votes for LARRY_ELDER: 207 Votes for KEVIN_PAFFRATH: 196 Votes for JOHN_COX: 194 Votes for KEVIN_FAULCONER: 214 Votes for NONE: 187 Which replacement candidate won the most votes? KEVIN_FAULCONER

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Perception of Others

Answered: 1 week ago

Question

Introduce and define metals and nonmetals and explain with examples

Answered: 1 week ago

Question

What is IUPAC system? Name organic compounds using IUPAC system.

Answered: 1 week ago

Question

What happens when carbonate and hydrogen react with carbonate?

Answered: 1 week ago

Question

2. Identify issues/causes for the apparent conflict.

Answered: 1 week ago