What should I edit or do in my code so that I will get the outcome? What could be edited in my code below to acheive the desired outcome? import java.util.Scanner; class program { } class prog1 extends program implements Runnable { private String nVoters = new String(""); public prog1 (String nVote){ nVoters = nVote; } @Override public void run(){ for (int x = 1; x <= input; x++){ System.out.println(" Voter " + x + "\t" + nVoters + "= " ); } } } public class Quiz2 { public static void main(String args[]){ Scanner sc = new Scanner(System.in); for (int x = 0; x < args.length; x++){ System.out.println(args[x]); } System.out.print("Enter number of voters: "); int input = sc.nextInt(); Runnable r = new prog1("Thread #1"); Thread Candidate1 = new Thread(r); Candidate1.start(); r = new prog1("Thread #2"); Thread Candidate2 = new Thread(r); Candidate2.start(); r = new prog1("Thread #3"); Thread Candidate3 = new Thread(r); Candidate3.start(); } }
What should I edit or do in my code so that I will get the outcome?
What could be edited in my code below to acheive the desired outcome?
import java.util.Scanner;
class program {
}
class prog1 extends program implements Runnable {
private String nVoters = new String("");
public prog1 (String nVote){
nVoters = nVote;
}
@Override
public void run(){
for (int x = 1; x <= input; x++){
System.out.println(" Voter " + x + "\t" + nVoters + "= " );
}
}
}
public class Quiz2 {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
for (int x = 0; x < args.length; x++){
System.out.println(args[x]);
}
System.out.print("Enter number of voters: ");
int input = sc.nextInt();
Runnable r = new prog1("Thread #1");
Thread Candidate1 = new Thread(r);
Candidate1.start();
r = new prog1("Thread #2");
Thread Candidate2 = new Thread(r);
Candidate2.start();
r = new prog1("Thread #3");
Thread Candidate3 = new Thread(r);
Candidate3.start();
}
}
![Command Prompt
Enter # of voters: 3
Voter 1 Thread #1 = 1
Voter 2 Thread #1 = 3
Voter 1 Thread #3 = 2
Voter 1 Thread #2 = 1
Voter 2 Thread #2 = 3
Voter 3 Thread #1 = 1 [Voting closed]
Voter 2 Thread #3 = 2
Voter 3 Thread #2 = 1 [Voting closed]
Voter 3 Thread #3 = 2 [Voting closed]
Candidate #1 has 4 vote(s)
Candidate #2 has 3 vote(s)
Candidate #3 has 2 vote(s)
Candidate #1 Wins!!!
Thread #1 Finished 1st
Thread #3 Finished last](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fca2180eb-e455-463f-9a9e-dd04cac7e66f%2Ff8392e09-0b8b-441b-9dfa-b3e5a908464b%2Fkqlkeev_processed.jpeg&w=3840&q=75)
![Create a program that allows users to enter the number of voters, then
generates 3 Threads.
Thread #1 will be named Candidate #1, Thread #2 as Candidate #2 and Thread #3 as
Candidate #3.
Each of the thread runs an iterative statement that generates “x" random numbers
between 1 to 3.
If the system generates a value of 1, that means a vote will be counted for
Candidate #1; if 2 vote will be added for Candidate #2 otherwise, it will be
credited to Candidate#3.
Note:
1. “x" (will be based on the "Number of voters")
2. If either of candidates have the same number of votes, then output text must say
"No Winner"](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fca2180eb-e455-463f-9a9e-dd04cac7e66f%2Ff8392e09-0b8b-441b-9dfa-b3e5a908464b%2Fndpnk4_processed.jpeg&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)