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

What is a banner grab?

Answers

Banner Grabbing is a technique used to gain information about a computer system on a network and the services running on its open ports. Administrators can use this to take inventory of the systems and services on their network.

Hope you find this helpful!
Brainliest and a like is much appreciated!

Write any two uses of ruler in word program

Answers

Answer:

1.It is used for draw the table, making results and assignments etc.

2.It is used for lining

Explanation:

Hope it helps

#CARRYONLEARNING

a client has requested adjustments to the arrangement and placement of elements on an image. what does the client want changed?

Answers

Considering the situation described above, the client wants the image's recipe to be changed.

What is the Image Recipe?

Image Recipes are characteristics of an image or picture. It includes features like shape, size, form, pattern, line, shadow, tone, color, contrast, positive space and negative space, etc.

Given that the client needs adjustments to the arrangement and placement of elements on an image, this is a request for a change in the image recipe.

Hence, in this case, it is concluded that the correct answer is "the client wants the recipe of the image changed."

Learn more about the Image Recipe here: https://brainly.com/question/1605430

6. Which devices of computer is known processing devices? las >​

Answers

Answer:

CPU is known as processing devices..!

What is the default folder for text file

Answers

documents or download

It depends where you install it to

Answer:

numbers are stored as characters

Explanation:

currently saved in if another folder

How has A.I. evolved and helped humanity in recent times?

Answers

Answer:

AI has helped many people in these days.

Explanation:

With AI adoption on the rise, the technology is addressing a number of global challenges.

Artificial intelligence is being used to help crack down on illegal activities.

It is helping to tackle over fishing in our ocean.

And it is even being used to address the issue of gender imbalance.

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:

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

Answers

Answer:

Tree

Explanation:

Sort the layout options for two types of masters in PowerPoint.

Answers

Answer:

The program photo is showing the correct answers and the correct place for the two that you missed.

Explanation:

Answer: ANSWER IS SHOWN CORRECTLY

Explanation:

I REALLY HOPE IT HELPS YOU!!!!!!!!!!!!!

THANK YOU & BE SAFE TOO!!!!!!!!!!!!!!!

Are theese speeds considered slow? (I used Ookla Speedtest)
PING ms
5
DOWNLOAD Mbps
86.54
UPLOAD Mbps
98.21

Answers

Answer:

No

Explanation:

They are pretty solid speeds and 5ms for ping is relativley low. If youre planning a large download (100+ gigs) I still recomend giving it a few

hours

gourmet pizza shop with a
Question 19
What type of competition does Netflix and a movie theater represent for each other?
A Weak direct competition
B Strong direct competition
C Indirect competition
D Global competition

Answers

Answer:

B.Strong direct competition.

Explanation:

Netflix can be viewed by anyone and at anytime.

Strong direct competition is the type of competition does Netflix and a movie theatre represent for each other. Hence, option B is correct.

What is Strong direct competition?

Direct competition occurs when multiple companies compete for the same market by offering the same product or service. There are several common examples of this.

One is the rivalry between McDonald's and Burger King; specifically, the Whopper and the Big Mac are bitter rivals. Direct competition is when two or more enterprises directly compete for the same potential market by offering almost similar goods or services.

Are actions taken by public authorities or governments to lessen the competitiveness of imported goods and services in comparison to locally produced ones. poor straight competitor The primary concentration is on one product.

Thus, option B is correct.

For more information about Strong direct competition, click here:

https://brainly.com/question/28739321

#SPJ2

What is my mistake on this code? (Python)

Answers

Answer:

Explanation:

bakugo;sup shoto i didnt know you go on here too

the coding has no problems just go and get deki kaminary

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.

what type is the combination of an integer and a string

Answers

Answer:

Concatenation.

Explanation:

Where are 'if' and 'else' statements shown when printing a document in a word processor?

Answer the question and then your task is to:

Write an algorithm or sequence of instructions that include the IF statement for the document being printed.

Answers

Explanation:

cpt price

If you are in the Slide Master view, what are the steps to add headers and footers?

Answers

Answer:

THat is the correct order.

Explanation:

outline how the appropriate features that may be used to ensure that the document is free of spelling and grammatically errors.​

Answers

Answer:

Answer

Since Sophie often makes a lot of

grammatical and spelling errors in her

document, it might be best for her to use

a feature available in Microsoft Word that

would help her better in understanding

what her mistakes are, which is

something that (D) Explain does.

Explain would tell Sophie which part of

her sentence is wrong, or what word

did she mistype, and what better way to

phrase a sentence to avoid fragmented

ones.

what does reporter failure mean on adt alarm system

Answers

On ADT alarm system, Failure trouble basically means that the monitoring service isn't working properly because of a communication issue with the system. As a result, the home or business is vulnerable.

How does the ADT alarm system function?

ADT will strategically place sensors throughout the home to ensure that each zone is covered. The motion then activates a reaction, such as a security light or a camera that begins recording, all through the wireless connection. The movement can also be reported to the ADT monitoring team.

ADT indoor security cameras come with phone security alerts, infrared night vision, a slim design, and secure WiFi. They provide a variety of views for live and recorded feeds and include professional installation.

Failure trouble on an ADT alarm system basically means that the monitoring service isn't working properly due to a communication issue with the system.

Learn more about the ADT alarm system, refer to:

https://brainly.com/question/28199257

#SPJ5

In the context of an ADT alarm system, "reporter failure" typically refers to a communication issue between the alarm panel and the monitoring center.

ADT alarm systems are designed to send signals or reports to a central monitoring station when an alarm event occurs, such as a break-in or a fire. The monitoring center then takes appropriate actions, such as contacting the homeowner or dispatching emergency services.

When the alarm system displays a "reporter failure" message, it indicates that the panel is unable to establish communication with the monitoring center. This can happen due to various reasons, including but not limited to:

Network or internet connectivity issues: If the alarm system relies on an internet or cellular connection to communicate with the monitoring center, any disruptions in the connection can result in a reporter failure.

Learn more about network on:

https://brainly.com/question/29350844

#SPJ6

Q44. Cell A20 displays an orange background when its value is 5. Changing the value to 6 changes the background color to green. What type of formatting is applied to cell A20

Answers

The type of formatting that is applied to cell A20 is called conditional formatting.

Conditional formatting in Excel Sheet enables an easier method of highlighting noteworthy cells or ranges of cells, displaying data by employing data bars, color scales, and icon sets that match particular variations in data.

A conditional format modifies the look of cells based on the conditions you set. The cell range will be formatted provided that the conditions are true; if otherwise, it will be false and the cell range will not form.

Learn more about conditional formatting here:

https://brainly.com/question/25051360

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!

Very few games have any sort of narrative, not even a simple one that involves setting the mood through color, sound, environment, and game mechanics.

A.
True
B.
False

Answers

Answer:

B. False

Explanation:

Numerous amount of games have narrative, there is an entire genres built around narratives. Any RPG game has a narrative and even bog standard FPS games have some sort of backstory and effects setting a mood.

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 the program below, which two variables have the same scope?

def usernameMaker (strFirst, strLast):
return strFirst + strLast[0]

def passwordMaker (strA, numC):
answer = dogName[0:3]
return answer + str(numC)

# the main part of your program that calls the function
username = usernameMaker ('Chris', 'Smith')
dogName = 'Sammy'
favoriteNumber = 7
password = passwordMaker (dogName,favoriteNumber)

strA and

Answers

Answer: numC

Explanation:

strLast and strFirst have their scope up to the function usernameMaker only. They don't have any relation with the variable strA in terms of scope.

numC has the scope same as the variable strA. They both have scope in the function passwordMaker

Therefore, correct answer is numC

Answer: num C

Explanation: got it right on edgen

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

????????????helpppp please

Answers

Answer:

I lab u pre haha jok

ano ka gold

Arrange the code so that the numbers are swapped.

Answers

Rand.int(your_num , your_num

How many things can a computer compare at one time?

Answers

Answer: billion of items at one time

Explanation: The computer is very capable of comparing items bulk at one time

A portfolio is a collection of materials that demonstrates your skills, abilities, achievements, and potential.
Question 22 options:
True
False

Answers

A portfolio is a collection of materials that demonstrates your skills, abilities, achievements, and potential.

A portfolio is a living and changing  collection of records that reflect your  accomplishments, skills, experiences,  and attributes. It highlights and  showcases samples of some of your best  work, along with life experiences, values  and achievements. A portfolio does not take the place of a resume, but  it can accentuate your abilities and what  you can offer in the chosen field.

Find out more about portfolio at: https://brainly.com/question/24811520

Lori wants to set up a SOHO network in her apartment. The apartment comes with a Gigabit Ethernet network already installed. Lori's notebook computer has an integrated wireless network adapter. Her printer has an Ethernet card, but is not wireless enabled. Your task is to select the appropriate devices and cables (without spending more than necessary) to set up a network that provides wireless access for Lori's laptop and wired access for her printer.

Match the labels for the components on the left to the locations where they need to be installed in Lori's home office on the right.

Answers

hi there!

Answer:

1. cat6 cable

2. wireless ethernet router

3. cat5e cable

Explanation:

1. you need a cat6 cable to be capable to deliver the gigabyte ethernet data to the network device.

2. you need a wireless device to provide wireless connection to her notebook.

3. for a printer no cat6 is necessary you can use cat5e cable and it will be enough.

hope this helps.

Connection to the gigabit ethernet network must be done with Cat6 Cable. Using the wireless ethernet router as the network device and connecting the cable to the printer must be done with Cat5e Cable.

We can arrive at this answer because:

The Cat6 Cable will be responsible for establishing a bridge between the gigabyte Ethernet and the network device, allowing data delivery to be made between the two systems.This connection must be made with a wireless device, to keep it more stabilized and it needs, mainly, for the notebook to receive the internet signal. This will be done using the wireless ethernet router.The printer needs a softer, less rigid connection, so a Cat5e cable will be a convenient option.

In this case, we can see that using these devices will allow Lori to have a more stable and efficient connection to meet her needs.

More information on network connection at the link:

https://brainly.com/question/8118353

A network of computers that provides access to information on the web.
Question 13 options:

Phishing

Internet

Antivirus Application

Modem

Answers

Answer:

Internet

Explanation:

I think it is Internet
Other Questions
Genes are sections of DNA that code for a particular trait. Genes are. A carbohydrates B. lipids C. proteins D. nucleic acids PLEASE HURRY I WILL MARK BRAINLIEST HELPPPPPPP PLSSSSS!!!!!! 100 pointsGiven: Angle T S R and Angle Q R S are right angles; Angle T Is-congruent-to Angle QProve: Triangle T S R Is-congruent-to Triangle Q R STriangles T S R and Q R S share side S R. Angles T S R and S R Q are right angles. Angles S T R and S Q R are congruent.Step 1: We know that Angle T S R Is-congruent-to Angle Q R S because all right angles are congruent.Step 2: We know that Angle T Is-congruent-to Angle Q because it is given.Step 3: We know that Line segment S R is-congruent-to line segment R S because of the reflexive property.Step 4: Triangle T S R Is-congruent-to Triangle Q R S becauseof the ASA congruence theorem.of the AAS congruence theorem.of the third angle theorem.all right triangles are congruent. alguien me pude dar la definicin de ambiente y usarla en una oracion porfa Write a word phrase to represent the numerical expression below. (7-3) 2 what health problems for humans are caused by volcanic eruptions please help with geometry problems Which of the following inferences does the chart support some colonial cities existed almost entirely to process raw materials with the last silver do mine there was less demand for slaves in Potosi silver mining creates many environmental hazards and spreads diseases when the mines gave out the Spanish abandon their colony entirely. A rubric explains how your teacher will determine how many points each test is worth over the course of a semester. Please select the best answer from the choices provided T F. 10 examples of monocot plant and 10 examples of dicot plants answer the following question: who created the Reynolds pamphlet PLEASE HELP!!Explain the physical and chemical properties of water, including its different phase changes. Why is water so critical for human life?Submission PLEASE HELP QUICKLY Determine the equivalent system for the given system of equations: 5x + 3y = 1 4x 5y = 4 Molly O'Rourke assembles computers for Radius Computer. She works 8 hours perday less 2 breaks at 15 minutes per break. She spends 45 minutes on eachcomputer. How many computers should she be able to assemble in one day? Which part of speech describes a verb?AdjectiveNounAdverbPrepositionHow does Mr. Stewart feel about good judgment and being in the right place at the right time?These traits have nothing to do with his line of work.The idea of good judgment does not affect his job.These traits used to be important, but they are no longer part of the job.These are essential skills that are very important in his line of work.How does making predictions while you are reading help you to be an active reader?It involves you in the story and asks you to think about what might happen next.It allows you to make up your own ending to the story.It helps you to read quickly and finish in less time.It involves you in outlining a nonfiction piece of writing.Which strategy is helpful when writing a book report?Read the book two or three times.Read the book quickly.Take notes while you are reading the book.Read only one chapter per day.Which of the following titles are examples of nonfiction?The Everglades and Santa PawsThe People's Republic of China and The EvergladesThe Wizard of Oz and The Mystery of the Purple PiratesThe History of Oklahoma and Danger on Vampire TrailWhat does the word immigrate mean?to come into a country or region for permanent residenceto regret for wrongdoingto have the legal right to the possession of somethingto deliver a message over long distances (789+890)=(2992) answer it and i give u a taco Find the area of the triangle qrs. Area = square units. (3x 1) : (x - 2) = x 2x (x4) , . The polygons below are similar. Find the value of y Find the circumference of a circle with a radius of 11.15 cm Lead has an atomic number of 82. Which statement describes all neutral atoms and ions of lead?A) Neutral atoms of lead must have 82 electrons. Ions must have 82 electrons, as well.B)Neutral atoms of lead must have 82 protons, but ions can have more or fewer.c) Neutral atoms of lead must have 82 neutrons, but ions can have more or fewer.D0 Neutral atoms of lead must have 82 protons. Ions must have 82 protons, as well.