Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program Election that computes the tally in a write - in election, and announces the winner. Since the votes are write - in

Write a program Election that computes the tally in a write-in election, and
announces the winner. Since the votes are write-in, there is no pre-determined set of
candidates. Whoever appears the most in the votes is the winner. The user enters the
individual votes, one vote per line, and ends entering with typing -1 or an empty line. To
Page 9 of 8
compute the tally, the program uses two arrays, a String [] variable (names), and an int
[] variable (count). Upon receiving a single vote, the program checks if the name on the
vote appears in names, and if it does, the program adds 1 to the value of the element in
count. If the name does not appear in names, the program extends both arrays by one
element, stores the name in names at the last position and store 1 in count at the last
position. In this manner, the two arrays will have the same lengths. The initial length is 0
for both arraysTask 4: Write a program Election that computes the tally in a write-in election, and
announces the winner. Since the votes are write-in, there is no pre-determined set of
candidates. Whoever appears the most in the votes is the winner. The user enters the
individual votes, one vote per line, and ends entering with typing -1 or an empty line. To
Page 8 of 8
compute the tally, the program uses two arrays, a String [] variable (names), and an int
[] variable (count). Upon receiving a single vote, the program checks if the name on the
vote appears in names, and if it does, the program adds 1 to the value of the element in
count. If the name does not appear in names, the program extends both arrays by one
element, stores the name in names at the last position and store 1 in count at the last
position. In this manner, the two arrays will have the same lengths. The initial length is 0
for both arrays.
Hint: You can use either Array or ArrayList.
Below is an example of how the program may run:
# Enter the votes, one vote per line. #
# End with either -1 or an empty line.#
Sam
Peter
James
sam
Sam
Peter
Sam
image text in transcribed

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

Recommended Textbook for

Databases Illuminated

Authors: Catherine M Ricardo, Susan D Urban

3rd Edition

1284056945, 9781284056945

More Books

Students also viewed these Databases questions

Question

Explain the pages in white the expert taxes

Answered: 1 week ago