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 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. Below is an example of how the program may runplease I need to demonstrate the code,I need some comments next to every single line

Answers

Answer 1

The election program illustrates the use of ArrayLists, loops and conditional statements.

ArrayLists are resizable arrays, while loops and conditional statements are used to perform repetitions and make decisions, respectively.

The election program written in Java, where comments are used to explain each line is as follows:

import java.util.*;

public class Main {

 public static void main(String[] args) {

     //This creates a Scanner object

   Scanner input = new Scanner(System.in);

   //This creates a string ArrayList for the names of the candidates

   ArrayList<String> names = new ArrayList<String>();

   //This creates an Integer ArrayList for the vote count of the candidates

   ArrayList<Integer> votes = new ArrayList<Integer>();

   //This declares name as string

   String name;

   //This gets input for the name of the candidates

   name = input.nextLine();

   //This is repeated until the user enters "-1"

   while (!"-1".equals(name)){

       //If name is in the list,

       if(names.contains(name)){

             //This gets the index of the name  

             int pos =names.indexOf(name);

             //This calculates the number of votes

             Integer value = votes.get(pos)+1;  

             //This adds the vote to the vote ArrayList

             votes.set(pos, value);

       }

       //If otherwise

       else{

           //This adds the candidate name to the name ArrayList

           names.add(name);

           //This adds 1 as the vote of the candidate to the vote ArrayList

           votes.add(1);

       }

       //This gets input for the name of another candidates

       name = input.nextLine();

   }

   //This prints the name of the election winner

   System.out.println("Winner : " +names.get(votes.indexOf(Collections.max(votes))));

 }

}

Read more about ArrayLists, loops and conditional statements at:

https://brainly.com/question/19504703


Related Questions

Oil refining is an example of:

Construction Production
Extractive Production
Domestic Production
Traditional Production

Answers

Answer:

i think the answer is B but i could be wrong...

Answer:

Extractive production

Explanation:

See

Oil refining denotes to after oil extraction situationFirst oil is extracted then gets refinedSo it's extractive production

Lacking in movement, action, or change, especially in a way viewed as undesirable or uninteresting�
Question 11 options:

Malicious

Algorithm

Static

Web Browser

Answers

Answer:

Static

Explanation:

I just took the test man!

how to connect apple pencil 2 to ipad 8th generation?

Answers

Answer:

That pencil doesn't adjust to that ipad because those two aren't compatible

Explanation:

Help!!
So I think that someone is tracking my truck with an apple airtag but I don't know for sure. The only apple product I have is an iPad and I don't know how to check if an airtag is near by!!

Answers

Answer:

Explanation:

   In iOS 13 or iPadOS 14 or later go to Settings > account name > Find My > Find My iPhone/iPad, and disable Find My network.

   In macOS 10.15 Catalina or later, go to the Apple ID preference pane, select the iCloud link at left, click the Options button to the right of the Find My Mac item, and uncheck Offline Finding or Find My network (the text varies by macOS version).

in reference to operating systems, what is spooling? what does it stand for? chegg

Answers

Answer:

Spooling is a process in which data is temporarily held to be used and executed by a device, program or the system. Data is sent to and stored in memory or other volatile storage until the program or computer requests it for execution. "Spool" is technically an acronym for simultaneous peripheral operations online.

computer science

describe 3 differences between the checksum and check digit:

Answers

Answer:

A check digit, also known as a checksum character, is the number located on the far right side of a bar code. The purpose of a check digit is to verify that the information on the barcode has been entered correctly.

A check digit, even comprehended as a checksum character, stands for the number found on the far right side of a bar code. The intention of a check digit exists to confirm that the information on the barcode contains been documented accurately.

What are the differences between the checksum and check digit?

A checksum in public can be any size, although generally, they exist some suitable number of bits for computation, such as 32. The more extensive the checksum, the wider the range of errors it can capture. For instance, the checksum utilized for credit card numbers will notice changed digits that exist after each other, but not reversed digits that exist split by a single digit.

All cryptographic hashes (like MD5, SHA, etc.) can be utilized as checksums, but not all checksums exist cryptographic. CRC-type checksums aren’t cryptographic, but they’re extremely quick to calculate, and so they exist generally utilized for things like hard drive checksums where you don’t require the cryptographic functionality, but you accomplish want to notice an extensive range of probable errors.

To learn more about checksum and check digit

https://brainly.com/question/14789699

#SPJ2

10. What Microsoft program is frequently used to develop pictorial representations
of a database's logical relationships?
A. Visio
B. Access
C. Excel
D. Word

Answers

Answer:

A. Visio

It's a "powerful tool for diagramming needs". In other words, pictures.

Question 1 Which portion of the PuTTY package allows you to perform file transfers using the SCP (Secure Copy) protocol?

Answers

There are different aspect of computing. The portion of the PuTTY package that allows you to perform file transfers using the SCP (Secure Copy) protocol is pscp.exe.

The pscp.exe tool commonly called the PuTTY Secure Copy Client is known to be the only portion of the Putty package that can let you copy files to and from remote computers through the use of the SCP.

Secure Copy (SCP)  is simply defined as a computer command that one can use in Linux to copy files from one computer to another on a network.  PuTTY is simply known to be a free implementation of SSH (and telnet) used for computer that running Microsoft Windows.

Learn more about the PuTTY package from

https://brainly.com/question/13171394

HELP PLEASE!!

which of the following is document content that displays at the top of every page?

Answers

Explanation:

that is a trick question if you need help ask your teacher

Answer:

Title

Explanation:

What Pre-Built PC should I get? I don't have a lot of money so I'm looking for cheap options.

Answers

Answer:

for a gaming pc i recommend better graphic cards and for streaming gpu you can find some good options online not exactly sure what model.

relevez le rôle principal de la peau dans l,organime humain. je suis bloquée aidez moi metci​

Answers

Answer:

language?

Explanation:

Within a master slide template, you can create a custom slide layout. Place the steps to complete this task in the correct order.

Answers

Answer: yes the above is correct

1. In the slide master tab, select insert layout.

2. Click rename, and name the new layout.

3. Choose new elements with Insert Placeholder.

4. Save the Changes.

5. Confirm by selecting Home, then Layout.

When a custom slide layout is created, the steps to complete this task in the correct order are as follows:

What do you mean by layout?

A layout refers to the parts of something that are arranged or laid out.

The steps to complete this task are as follows:

In the slide master tab, select insert layout.Click rename and name the new layout.Choose new elements with an Insert placeholder.Save the changes.Confirm by selecting home and then the layout.

Learn more about Layout here:

https://brainly.com/question/1327497

#SPJ2

Arrange the code so that the numbers are swapped.

Answers

Rand.int(your_num , your_num

Michaela has been tracking the temperatures of the dirt, pond water, and air near her home for a science investigation. She is ready to analyze the data to prepare for her science report. Based on each application’s strengths and weaknesses, which one would be the best to choose for this task?

Answers

Answer:

The science of investigation

Explanation:

hope it help

Why there should be laws against using phones and

driving?

Answers

Answer:

There should be laws against using phones & driving because you can get into an accident & you are not paying attention to the road & it's surroundings.

Explanation:

It is for your safety & other peoples safety around you.

WHEN IS THE DESIGN PROCESS FINISHED IN ENGINEERING?​

Answers

Answer:

I think answers is it never ends

This is an image of the ...................... Topology. * If you get it right i will mark you brainlist ​

Answers

Answer:

Tree

Explanation:

In the program to evaluate passwords, you gradually built a message to display to the user. What did you add to the end of each message string to start each message on a new line?

message = message + "Your password needs an uppercase letter. _____ "

\endline

\e

\n

\newline

Answers

You need to add \n to start a new line

The option that one need to add to the end of each message string to start each message on a new line is \n.

What is a message string?

This is known to be a kind of running aspect of text messages that relates to one topic or any question.

Based on the program written above, the option that one need to add to the end of each message string to start each message on a new line is \n as it is the one that will give the best result.

Learn more about program  from

https://brainly.com/question/1538272

#SPJ2

Kari needs to change the brightness and contrast on an image she has inserted into a Word document. Which group should she use to do this? Adjust Picture Styles Arrange

Answers

Answer:

adjust

Explanation:

it can be found in the top left corner

How to recover permanently deleted photos from gallery?

Answers

Answer:

it's technically impossible to recover permanently deleted photos

but if you have a copy of the photo or maybe have backup that would help.

I'm sorry if my answer isn't much help

What is my mistake in this case?

Answers

Answer:

I think it suppose to be #print out house

Answer:

i guess take the hint, bro.

Explanation:

what type is the combination of an integer and a string

Answers

Answer:

Concatenation.

Explanation:

I WILL GIVE BRAINLIEST TO WHOEVER HELPS ME

I keep pressing the "fn" key or "function" key and the disable / enable touchpad button
fn + f9 = enable/disable touchpad
but all it's doing is disabling it, everytime I press to enable it just keeps saying "touchpad has been disabled"

Answers

Assuming you're using Windows 10/11, navigate to settings --> Bluetooth and settings --> Touchpad (Or just search Touchpad on your search bar) --> Toggle the touchpad on.

Hope this helps! :)

My sister told me an extremely funny joke. what is the direct object for this sentence ?

Answers

Answer:

Explanation:

Can someone plss help me!!

Answers

Answer:

HTML elements are delineated by tags, written using angle brackets.

Explanation:

Tags such as <img /> and <input /> directly introduce content into the page.

which type of writing is most commonly used in the field of information technology

Answers

Answer:

Technical writing

.........

the windows logon process has unexpectedly terminated

Answers

Answer

Windows corrupted

Explanation:

Try buying a new windows or resetting your laptop/pc

or your service failed to register/start

Windows login allows user accounts to log on to the system by opening the subscriber notification database and initiating user-level operations. The system may start with reduced functionality if the system resources required for Windows logon are insufficient.

What windows logon process has unexpectedly terminated?

In order to read the list of user accounts that are set up for the machine, the Windows operating system reads the registry at logon.

The Windows logon page won't appear if the data can't be read, making it impossible for users to sign in to Windows. The level of registry damage determines whether Windows can finish the startup procedure or not.

You will need to boot the computer into the Recovery Console rather than Windows in this circumstance. Use the Startup Repair tool after entering the Recovery Console. For Windows installations that won't boot, Startup Repair automates frequent diagnostic and repair activities.

Therefore, All logon attempts, however, will be blocked if the Windows registry is seriously damaged. Windows crashes when you try to log on, and it restarts after that.

Learn more about Windows here:

https://brainly.com/question/6969788

#SPJ5

This type of RAID implementation uses its own Central Processing Unit (CPU) for calculations on an intelligent controller card by:

Answers

RAID implementation uses its CPU for calculations on an intelligent controller card by a hardware implementation.

Basically, a hardware implementation refers to a job is done using a physical device or electronic circuit rather than been done automatically by the computer program.

Hence, through a hardware implementation, the RAID implementation is able to use its CPU for calculations on an intelligent controller card

Read more about hardware implementation

brainly.com/question/25803633

Whats wrong with this and how do I fix it?

Answers

Answer:

this happened to me before.. there isn't anything wrong you just have to wait a little

Explanation:

it is defined as the interloping of yarn with the use of a hook to make a design . A smocking B knitting C crocheting D embroidery​

Answers

Answer:

letter C

Explanation:

because the crocheting is defined as the interloping yarn and use to make and made a design to excellent.

Other Questions
(a ng questions. What are the types of forest found in Nepal? Differentiate between the Tropical Evergreen Forest and the Temperate Deciduous Forest based on their location and features. Economics (Microeconomics)!!! There has been a global shortage of electronic chips in recent years. Write a short essay in which you discuss this situation by using the economic concepts, tools, and analysis you have learned in this course( Microeconomics).Instructions: The essay must have a length between 250-500 words, it must be well- organized, it must include the causes of this shortage and its effects on countries economies as well as on the global economy overall. 29) The description of life on the farm creates a tone that isA) sadB) sentimentalC) serious.D) sinisterWill give brainliest PLEASE HELP I"LL GIVE BRAINLEAST Rico paid $180 sales tax on his new $2,400 motorcycle. What was the sales tax percentage rate where he bought his motorcycle?7.0% tax rate7.5% tax rate8% tax rate6.5% tax rate HELP PLEASE ITS AN EXAM!!Which organisms are most closely related?O species A and BO species A and CO species B and CO species C and D Which represents the explicit formula for the arithmetic sequence an = 7 - 3(n - 1) in function form? Does technology always follow the science, yes or no and explain the reason your choice The perimeter of a square is 16 inches what is the length of each side? Read the first stanza of the poem The Raven by Edgar Allan Poe. Which phrase helps create the gloomy tone of the poem? Once upon a midnight dreary, while I pondered, weak and weary, Over many a quaint and curious volume of forgotten lore While I nodded, nearly napping, suddenly there came a tapping, As of some one gently rapping, rapping at my chamber door. "Tis some visitor," I muttered, "tapping at my chamber door Only this and nothing more." (Help me please!!)Write the equation of each linear relationship in slope-intercept form. (Convert the slope to decimal form.)X: 25, 35, 45, 55Y: 94. 88, 82, 76 Which of the following is true of grinding duringdigestion?A. The process of grinding is a physical changethat takes place in the mouth during digestion.B. The process of grinding is a chemical changethat takes place in the mouth during digestion.C. The process of grinding is a physical changethat takes place in the small intestine duringdigestionD. The process of grinding is a chemical changethat takes place in the small intestine duringdigestion Which of the following statements best summarizes the overall meaning of "charming billy"A. US soldiers in the Vietnam War were proud to represent their country.B. Soldiers from the Vietnam War were less effective because some of them has been drafted.C. The US military did not properly prepare soldiers for the fighting conditions in Vietnam.D. The soldiers in the Vietnam War needed training in both physical and psychological survival tactics. Please help me I need to finish this and I can't find the answerQuestion # 1Multiple ChoiceA holistic approach to health care involves _____.treating all of the current illnessescreating special care planslooking at all the patients problemsfocusing on the general wellness of patientsQuestion # 2Multiple ChoiceGeriatric means _____.relating to the illpertaining to the elderlylong-term careindividuals with multiple illnesses Help help business please pelsss Darren looks up at night and sees a bright object with a tail moving quickly across the sky. What is the most likely object that Darren saw? A. an asteroid B. a meteor C. a comet . D. a cupid A student is trying to classify an unidentified, solid gray material as a metal or a nonmetal. Which question will best help the student classify the material?. A local store buys used video games. For each game bought, they will pay $18 less than the original price paid for the game. Which expressions represent the total amount Jordan will receive if he sells n games that originally cost d dollars each? Select two options.d (n minus 18)n (d minus 18)d + n minus 18d n minus 18 n18 n minus d n 3. How does the setting in paragraphs 26-27 help develop theplot?The last dog 1. Twelfth Night contained a lot of figurative language. What is it?A) A figure of speech where the author refers to a subject matter by way of a passing referenceB) The process wherein an author introduces and then describes a characterC) A form of writing where the writer uses exaggeratedly complex sentences to convey a meaning that could have been conveyed through a much simpler sentenceD) Phrasing that goes beyond the literal meaning of words to get a message or point across David's Coffee Shop makes a blend that is a mixture of two types of coffee. Type A coffee costs David $4.45 per pound, and type B coffee costs $5.85 per pound. This month, David made 123 pounds of the blend, for a total cost of $643.95. How many pounds of type B coffee did he use?