Answered step by step
Verified Expert Solution
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 mainString args
Scanner enter new ScannerSystemin;
ArrayList arrayname new ArrayList;
ArrayList arraycount new ArrayList;
System.out.printlnEnter your candidates' names, or enter to end the program:";
while true
System.out.printEnter name of your candidate: ;
String name enter.nextLine;
if nameequals name.isEmpty
break;
if arraynamecontainsname
int i arrayname.indexOfname;
int j arraycount.geti;
j;
arraycount.seti j;
else
arrayname.addname;
arraycount.add;
enter.close;
System.out.println
Number of votes for each candidate:";
for int k ; k arrayname.size; k
System.out.printlnarraynamegetk received arraycount.getk votes;
Integer mostVotes Collections.maxarraycount;
System.out.println
Winners:;
for int n ; n arraycount.size; n
if arraycountgetnequalsmostVotes
System.out.printlnarraynamegetn is the winner with mostVotes votes";
make flowchart of this code
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started