Hello, I'm attempting to do a Java question on Voting system.

The idea goes like this:

There are 10 contestants in a singing competition. The java program will generate random 10 votes for any of the 10 singers. Some votes may appear more than once. (e.g contestant 4 may get 2 votes). This is done with Random number. (Contestant will be numbered from 0 to 9)

Write a thread class VoteThread to run such that it displays the contestant number and the votes.

Here is the desired output:

Here are the votes:

5 1 2 5 5 4 7 2 9 0

Contestant 5 has 1 votes so far

Contestant 0 has 1 votes so far

Contestant 1 has 1 votes so far

Contestant 4 has 1 votes so far

Contestant 2 has 1 votes so far

Contestant 5 has 2 votes so far

Contestant 9 has 1 votes so far

Contestant 7 has 1 votes so far

Contestant 5 has 3 votes so far

Contestant 2 has 2 votes so far

Here are the results:

Contestant 0 has 1 votes

Contestant 1 has 1 votes

Contestant 2 has 2 votes

Contestant 3 has 0 votes

Contestant 4 has 1 votes

Contestant 5 has 3 votes

Contestant 6 has 0 votes

Contestant 7 has 1 votes

Contestant 8 has 0 votes

Contestant 9 has 1 votes

Winner is Contestant 5

Here are my codes so far

Test:

Code:`import java.util.*;`

public class Test{

static final int TOTAL = 10;

public static void main (String[] args){

int [] votes = new int[TOTAL];

int [] results = new int[TOTAL];

Random contestantvote = new Random();

System.out.println("Here are the votes: ");

for(int i=0; i<votes.length; i++) {

votes[i]=contestantvote.nextInt(TOTAL);

System.out.print(votes[i]+" ");

}

System.out.println();

VoteThread TOTAL = new VoteThread(votes,results);

TOTAL.start();

try

{

TOTAL.join();

}

catch (InterruptedException e) {}

System.out.println("Here are the results: ");

/* for(int counter=0;counter<votes.length;counter++) {

System.out.println("Contestant "+counter+" has "+votes[counter]+" votes");

}*/

}

}

VoteThread:

I'm stuck with producing the output properly for "Contestant x has y votes so far". Cant seem to formulate it.Code:`public class VoteThread extends Thread{`

private int votes [];

private int results [];

public VoteThread(int votes[], int results[]){

this.votes = votes;

this.results = results;

}

public void run() {

for(int count=0; count<votes.length;count++)

{

results[0] = results[0] + 1;

System.out.println("Contestant "+ votes[count] +" has "+results[0]+ " votes so far");

try{

sleep(355);

}catch (Exception e){}

}

}

}

Can you please point me in the right direction to produce the final results of the voting system as well ?

Thank you