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

In Super Mario Bros., you become Mario and your friend is Mario’s younger brother Luigi. Your job is to race through Mushroom Kingdom to save Princess Toadstool and avoid the enemy, Bowser. You can jump from and to different objects, picking up coins and other items to help you on your journey through the levels. What game genre (or combination of genres) best describes this game?

A.
strategy simulation
B.
action adventure
C.
RPG
D.
sports action

Answers

B action adventure ——————

Why would you add learning inside the app? A. To add contextual help for each page in the app B. To contact Salesforce support C. To link to your company’s onboarding resources D. To add resources about working in Salesforce Classic E. A and C

Answers

There are different reasons why there was the addition of learning to the app. The reasons why you would you add learning inside the app is that:

To add contextual help for each page in the app.

To link to your company’s onboarding resources.

Salesforce Learning Paths is known to result in bringing out the power of learning straight into the app.

It can help companies to update their teams as they function or work in Salesforce.

Through the use of the Learning Paths, firms whether big or small and other industry can update or equip their employees with timely, personalized learning in the flow of work.

This can therefore help employees of all experience levels by boasting their skills and in turn increase their productivity.

Learn more about Salesforce from

https://brainly.com/question/7452075

what type is the combination of an integer and a string

Answers

Answer:

Concatenation.

Explanation:

Select all that apply
photoshop question

Form is gives the object this look?

a. Flat

b. Textured

c. Dark

D. 3d

Answers

It should be D and B

I'm confused as to if subclasses can call the supers without any implementation and what the right answer is

Answers

Answer:

E

Explanation:

Since Example1 and Example2 inherit from Example0, all classes have the method doNothing() at their disposal, so you can call it from e0, e1 and e2.

However, the arguments of this method are Example1 and Example2, so you cannot pass Example0 as a first argument, and you cannot pass Example0 or 1 as a second argument. That only leaves answer E.

You can call the inheritance relation an "is a kind of" relation. So Example1 is a kind of Example0, and Example2 is a kind of Example1, but also Example2 is a kind of Example0.

Now you can understand why e2 can be passed as an argument for Example1, because e2 is a kind of Example1.

Can you help me to write a code with functions,arrays,and pointers in c++?
It can be a basic game or an interesting program.
But a little bit complicated :)
Please I need help :(((​​

Answers

Answer:

Your search for complete and error-free projects in C and C++ ends here! Here, we’ve enlisted all the mini-projects, projects, games, software and applications built using C and C++ programming language — these are the projects published in our site or available with us at the moment. You can download all these projects (with source code) for free; make sure to check their individual post description as well.

First thing, most students learn C and C++ as their first programming language. They quickly become able to write programs that include functions, arrays and pointers, file handling and data structure, etc. But, when it comes to building a mini-game, an application, or a small project, incorporating all these features in one compact program becomes difficult.

In such case, reference projects always come in handy. The C and C++ projects published in our site will teach you how to get started, give you ideas and topics regarding your project, and sharpen your programming skills in C and C++. Here, you’ll find short and simple as well as long and complicated projects.

IT ethics are rules, policies, or principles that guide the behavior of IT professionals.
Question 7 options:
True
False

Answers

Answer: true

Explanation: true

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.

Draw truth table for the following logic circuit:

(Please I really need help with this)

Answers

Keep Scrolling! :D

[tex] \rule{999pt}{66646pt}[/tex]

Write steps of the following operations.
a. applying borders and spacing
b. create a folder​

Answers

Answer:

b

Explanation:

first right click on an empty space

click on new from the pop up menu

finally click on new folder

what are quantum computers and it uses​

Answers

Answer: Quantum computers are machines that use the properties of quantum physics to store data and perform computations

Levi wants to run 5 commands sequentially, but does not want to create a shell script. He knows that each command is going to take approximately 20 minutes to run individually. However, he would like to go to lunch 15 minutes from now. He knows that he can type all of the commands on the same line and separate them with a certain character to run them sequentially.

Required:
Which character can he type after each command to have them run one after the next without requiring further input from him?

Answers

Answer:

um

Explanation:

what subject is this again?

HELP ME PLEASE

explain 2 threats to data that can arise when a pc is not connected to the Internet​

Answers

Explanation:

Threats

Computer Security Threats are possible dangers that can affect the smooth functioning of your PC. These may be a small piece of adware or a harmful Trojan malware. In the present age, computer security threats are constantly increasing as the world is going digital. computer security threats

Types of Computer Security Threats

There are several types of computer security threats such as Trojans, Virus, Adware, Malware, Rootkit, hackers and much more. Check some of the most harmful types of computer Security Threats.

COMPUTER VIRUS

A Computer Virus is a malicious program, which replicates itself and infects the files and programs of your PC and can make them non-functional.

COMPUTER WORMS

A self-replicating computer program that spreads malicious codes, computer worms make use of the network to send copies of the original codes to other PCS. It can also go to the extent of sending transferring documents utilizing the email of the user.

SCAREWARE

Scareware is a malware that tricks victims to buy software by displaying fake virus alerts. A scareware infected PC may get pop-ups of fake malware threats and to get rid of those, users are prompted to purchase a fake anti-malware software.

KEYLOGGER

Also known as a keystroke logger, Keyloggers can track the real-time activity of a user on his computer. Keylogger runs in the background and records all keystrokes made by a user and passes the information to the hacker with the motive to steal password and banking details.

ROOTKIT

A rootkit is considered extremely dangerous as they appear to be legitimate files and deceives the computer user. Rootkit masks viruses and worms and makes them appear as necessary files. These are very difficult to remove and only an antivirus with the anti-rootkit feature can remove a rootkit.

Tips for Best Computer Security

For best computer security, you must follow certain guidelines, which are also called computer best practices. 1. Use the best antivirus software, which not only provides protection to your PC but also internet protection and guards against cyber threats. 2. Do not download untrusted email attachments and these may carry harmful malware. 3. Never download software from unreliable sites as they may come with a virus that may infect your system as soon as you install the software.

a data visualization tool that updates in real time and gives multiple outputs is called

Answers

Answer:

A data dashboard

Explanation:

A data visualization tool that updates in real time and gives multiple outputs is called data dashboard.

Why is data dashboard required?

A data dashboard is a tool that many businesses use to monitor, examine, and present data—typically to acquire understanding of the general health of an organisation, division, or particular procedure.

Businesses utilise an interactive analytical tool called a data dashboard to analyse and monitor the effectiveness of their plans using high-quality KPIs.

These tools give businesses access to real-time data so they can extract useful insights and guarantee ongoing growth.

Making it simpler for data analysts, decision-makers, and everyday users to understand their data, acquire deeper insights, and make better data-driven decisions is the main goal of a data analytics dashboard.

Data dashboard is a term used to describe a real-time updating, multi-output data display tool.

For more details regarding a data dashboard, visit:

https://brainly.com/question/29854747

#SPJ6

Tynker has a particular layout, with the blocks on the left, editor in the middle, and output on the right. Which word best describes this screen layout?
block-based
interface
editor
player

Answers

Interface best describes the layout of the screen.  This is done by designers

in which they help to design the appearance and style of various software

and devices.

These characteristics help to ensure the users find them friendly and easy to

navigate through when performing various operations .

In this scenario, we were told that the layout has blocks on the left, editor in

the middle, and output on the right which are designs for easy navigation on

Tynker.

Read more about Interface here https://brainly.com/question/5080206

Answer:

interface

Explanation:

1. Explain 'Computer Ethics" ?



plz following me ​

Answers

Answer:

Computer ethics is a part of practical philosophy concerned with how computing professionals should make decisions regarding professional and social conduct.  or the computer experts making the decision regarding the social and professional behaviour while working while with the computer tools and technology is called computer ethics.

Explanation:

HELP PLZ 50 POINTS
What code would add a new array item named "home" to the array below?

var titles = ["score", "points"];

titles.put("home");
titles.push("home");
titles.set("home");
array.push("home");

Answers

Answer:

titles.push("home");

Explanation:

        It depends on if you want to change the original array or not, but since you are just adding on I think this is the correct option.

        "... 5 ways to add an item to the end of an array. Push, splice, and length will mutate the original array. Whereas concat and spread will not and will instead return a new array. Which is the best depends on your use case" (www.samanthaming.com)

[] Attached is from the same source

-> I think this is correct

Have a nice day!

     I hope this is what you are looking for, but if not - comment! I will edit and update my answer accordingly. (ノ^∇^)

- Heather

How many letters is in whatyoudoingareyougood

Answers

Answer:

43847823773 letters

Explanation:

haha to easy

Answer:

22 letters, 6 words.

:) hope this helps! <3

Which of the following rules need to be followed when using variables?
Choose all that apply.

Answers

Answer:

- All variable names must begin with a letter of the alphabet or an. underscore( _ ).

-After the first initial letter, variable names can also contain letters and numbers.

-Uppercase characters are distinct from lowercase characters.

-You cannot use a C++ keyword as a variable name.

Answer:

Variable names must begin with a letter or an underscore( _ )

After the first initial letter, variable names can also contain letters and numbers. ...

Uppercase characters are distinct from lowercase characters. ...

You cannot use a keyword as a variable name.

Explanation:

What is the correct method to reset the contents of the CMOS NVRAM on HP Desktop / Workstation computers after the AC power has been disconnected

Answers

It should be noted that in order to reset the content of the CMOS NVRAM on HP Desktop, one can turn off the power and turn it back on while the person is holding the shift key.

It should be noted that the non-volatile RAM simply means a complementary metal-oxide-semiconductor chip that can be found inside computers which is vital for storing information.

To reset the content of the CMOS NVRAM on HP Desktop, one can turn off the power and turn it back on while the person is holding the shift key.

Learn more about computers on:

https://brainly.com/question/24540334

The voltage/potential difference in a circuit is 12 volts, calculate the current that is flowing through the circuit if the resistance is 48 Ohms.

Answers

Current (I) = 0.25 ampere (A)

Power (P) = 3 watt (W)

Current (I) = 0.25 ampere (A) Power (P) = 3 watt (W) Steps: I = V R = 12 volt 48 ohm =  0.25 ampere (A) P = V2 R = (12 volt)2 48 ohm =  3 watt (W)

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!

Write a program to print sum on first 10 natural numbers.
#include
int main()
{
int i, sum;
for(i=1;i<=10;++i);
{
sum =sum + i;
}
printf("The sum is = %d",sum);
}

Answers

A program that prints the sum on the first 10 natural numbers is:

int sum=0;int i=1;for(i=1; i <= 10 ; i++) // the value of i will be from 1 to 10{sum=sum+i; //each number will get added to the variable ‘sum’}System.out.println(sum); //

What is a program?

A computer program in a programming language is a set of instructions and commands written in a language that a computer can execute or understand. 

Using the For Loop program, the variables of the first 10 natural numbers can be written as:

int sum=0;int i=1;for(i=1; i <= 10 ; i++) // the value of i will be from 1 to 10{sum=sum+i; //each number will get added to the variable ‘sum’}System.out.println(sum); //

Learn more about writing a program here:

https://brainly.com/question/23275071

what hash format are modern windows login passwords stored in?

Answers

User passwords are hashed and stored in a registry hive as either an LM hash or an NTLM hash. This file requires System privileges to view.

What are the windows?

Microsoft created Windows as an operating system. The operating system is responsible for allowing to use a computer. Windows comes preloaded on the majority of new personal computers (PCs), which contributes to its status as the world's most popular operating system.

A window is a distinct viewing area on a computer display screen that is part of a system that allows multiple viewing areas as part of a graphical user interface (GUI). As part of a windowing system, windows are managed by a windows' manager.

Therefore, user passwords are hashed and stored as either an LM hash or an NTLM hash in a registry hive.  

Learn more about the windows, refer to:

https://brainly.com/question/13502522

#SPJ5

what is control structure write it's types​ .

Answers

Answer

Defination-:

A control statement is a statement and a statement whose execution its control.

Types-:

Selection StatementIteration StatementUnconditional branching Statement

You have created a slide that is functional, but a bit on the boring side. In five to ten sentences, describe changes you would make to the slide to make it more effective.

Answers

To make my slide more effective, I would add two or three pale colors that would decorate it while not distracting viewers from the topic. I would also add visuals that would engage viewers and give them a better understanding of the material. Additionally, I would include more examples and details to give viewers a clearer picture of what I would be attempting to convey to them. The final thing I would do to the slide would be to organize it in a way that would present information well. In conclusion, in order to improve the effectiveness of a slide, I would make changes to its design and layout that would make it easier for viewers of the slide to understand.

Answer:

I would add colors to the backround of the slide to decorate it and make sure it is not distracting, Use different fonts but dont make it too fancy.

Explanation:

Your Welcome

Not every design choice in your game interface requires having a thought process behind it.
True
False

Answers

Answer:

true

Explanation:

cause every design have it's own thought process and we also have our choice

Answer:

true

i agree with the person that answerd

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

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

Answers

Answer:

Technical writing

.........

What are some of the restrictions to muscle wire?

Answers

Answer:

Muscle Wire is an extremely thin wire made from Nitinol (a nickel-titanium alloy) that is known for its ability to contract when an electric current is applied.Although thin and lightweight, one of the most amazing things about Muscle Wire is that they can lift many times their weight and are able to do 100 times more work per cycle than the human muscle. This material is easy to use, small in size, operates silently, has a high strength-to-weight ratio, and is easily activated using AC or DC power. This technology is ideal where mechanics require minimization, such as electronic textiles projects, robotics or nano-applications.Muscle Wire is an extremely thin wire made from Nitinol (a nickel-titanium alloy) that is known for its ability to contract when an electric current is applied.

Other Questions
Reflecting on the memoir Night, what role do you think fear played in Elies life? Whats your opinion of Elie Wiesels overall experiences? What impact did his memoir Night and his interview withOprah have on you? Meaning, what were your takeaways? Why do you think it is so important to study history and thedetails of the Holocaust? in the medicine bag, why does grandpa collapse after arriving at the house? 8(3x 6) = 6(4x + 8) why do we need to study thermodynamics? T im A ngoi (O) k cc tip tuyn AB, AC vi ng trn (B v C l cc tip im), BC ct OA ti D, trn cung nh BC ly E, ED ct (O) ti F chng minh gc BAE = gc CAF what was one of the first taxes to be levied on the colonists Please answer this question Step by Step method.If it is correct you will get a thank you and 5 stars from me. American factories are making more than the American people can use; American soil is producing more than they can consume. Fate has written our policy for us; the trade of the world must and shall be oursAccording to the document, what was one effect of industrialization in the United States?A.Factories and Farmers were producing more goods and crops than Americans could consumeB.Overcrowding in citiesC.Low wages for factory workers Leticia reads the temperature of a solution in a lab experiment. The temperature of the solution is 6.1F. After 6 hours, she reads the temperature of the solution again. The temperature of the solution is now 1.7F. Leticia plots the points on a number line to determine the temperature change between these two readings. How much did the temperature decrease? Enter your answer as a decimal in the box. When one personstruggles, we all struggle.When one persontriumphs, we all triumph.Do you believe in thisstatement? Why or whynot? can u plz answer this ill give brainliest I need help ASAP . The ratio of good guys to bad guys was 15 to 4. If there were 75 good guys, how many bad guys were there ? Can someone solve this, please? AND FAST What did Thomas Jefferson and the anti-federalists require before they 2 pointsagreed to ratify the Constitution?Article 4 of the ConstitutionBill of RightsPreamble to the ConstitutionAmended Articles of Confederatioin (a) A straight line L, whose equation is 3y - 2x = -2 meets the x-axis at R Determine the co-ordinates of R. Read the passage from "The Spanish Civil War.Four months later the morale of the increasingly hard-pressed republicans received another major blow when Britain, France, and Italy acknowledged Hit's preeminence in Europe by accepting his d at Munich that deprived Czechoslovakia of its borderland defenses. The that triumph was followed by Franco's massive invasion of the province of Catalonia and the capture of Barcelona, its major city. In March of the following year, a nationalist offensive seized in two days Madrid, and the last loyalist forces surrendered on April 1.What is the authors most likely purpose for writing this particular passage?A. to describe solutions for ending the Spanish Civil WarB. to explain a cause-effect relationship of events in the Spanish Civil WarC. to describe a sequence of events during the Spanish Civil WarD. to explain similarities and differences in the Spanish Civil War Draw a diagram that shows how Mark and Gina can model the positions of the Sun, Earth, and the Moon, and their orbital paths, during a solar eclipse. You must use all of the tools in your design: lamp, tennis ball, golf ball, and yarn. Coffee then:45 calories Coffee now:270 calories what is the percent of increase does anyone know this answer? ______ is an example of a TCS food.A whole watermelonChickenBreadUncooked (dry) rice