Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class Election { public static void main ( String [ ] args ) { Scanner enter = new

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Election {
public static void main(String[] args){
Scanner enter = new Scanner(System.in);
ArrayList arrayname = new ArrayList<>();
ArrayList arraycount = new ArrayList<>();
System.out.println("Enter your candidates' names, or enter -1 to end the program:");
while (true){
System.out.print("Enter name of your candidate: ");
String name = enter.nextLine();
if (name.equals("-1")|| name.isEmpty()){
break;
}
if (arrayname.contains(name)){
int i = arrayname.indexOf(name);
int j = arraycount.get(i);
j++;
arraycount.set(i, j);
} else {
arrayname.add(name);
arraycount.add(1);
}
}
enter.close();
System.out.println("
Number of votes for each candidate:");
for (int k =0; k < arrayname.size(); k++){
System.out.println(arrayname.get(k)+" received "+ arraycount.get(k)+" vote(s)");
}
Integer mostVotes = Collections.max(arraycount);
System.out.println("
Winner(s):");
for (int n =0; n < arraycount.size(); n++){
if (arraycount.get(n).equals(mostVotes)){
System.out.println(arrayname.get(n)+" is the winner with "+ mostVotes +" votes");
}
}
}
} make flowchart of this code

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_2

Step: 3

blur-text-image_3

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

Expert Performance Indexing In SQL Server

Authors: Jason Strate, Grant Fritchey

2nd Edition

1484211189, 9781484211182

More Books

Students also viewed these Databases questions

Question

Describe forecasting requirements.

Answered: 1 week ago