Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In order to accomplish this you will need to modify the program in the following ways: Notice that this version, unlike the version in the

In order to accomplish this you will need to modify the program in the following ways:
Notice that this version, unlike the version in the book, will keep asking the user for a file (and then process the ballots in that file) until the user types in "quit" (which will cause the program to end instead of processing any more files).
Modify the Ballot class to have an isEmpty method that returns true when this ballot has no candidates left (it should return false if the ballot still has 1 or more candidates left)
Modify the Ballot.getCandidate() method to return "none" when the ballot has no candidates left
Then modify the TallyVotes program to account for potentially empty ballots.
It is possible that the input file will contain blank lines because a voter didn't pick any candidates, so include a test that ignores blank lines in the input file.
Modify the method that eliminates candidates so that it removes from the list of ballots any ballots that become empty.
(That way the percentages will be reported correctly on the next round of tallying)
Remember that the winner must get 50%+1 of the total number of original ballots (not just 50% of the most recent round). You will need to modify the code so that the original number of ballots is used to calculate the winner.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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