ould 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 + "= " );

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

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
Transcribed Image Text: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
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"
Transcribed Image Text: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"
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY