Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are working as a programmer for developing a game show. The host of the show

ID: 3853000 • Letter: Y

Question

You are working as a programmer for developing a game show. The host of the show asked you to develop a Java program that will help the game show running smoothly. The rules for the show is that it will ask the player a couple of questions. If the player can answer the question correctly in 10 seconds, he/she will score one/1 point. If the player’s answer is wrong or if he/she does not answer the question within 10 seconds, the correct answer is displayed and the player does not score any points. After getting an answer or running out of time, the next question is displayed. From the rules above you can get the sense this program needs to run in parallel manner to handle different tasks at the same time. You can use locks/conditions to ensure thread synchronization. We suggest that you should use three threads to handle three tasks.

Below is a skeleton of logic that you might follow:

printQuestion thread{

// start timer thread

// wait for answer or timeout

// save response from user

// print “correct”, “wrong” or “timeout”

}

reader_thread{

// check for end of program

// read answer;

// move answer to global variable

// release printer thread

}

timer_thread(int num) {

// wait 10 seconds; you can use sleep() here

// still waiting for this question?

// put TIMEOUT value as response

// release printer thread

}

Explanation / Answer

import java.util.Random;
import java.util.Scanner;
public class table {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
Random generator = new Random();
int user_door, open_door, other_door, prize_door;
prize_door = generator.nextInt(3) + 1;
other_door = prize_door;
System.out.println("*** Welcome to the game show! ***");
do{
System.out.println("Select the door (1, 2, or 3): ");
user_door = scan.nextInt();
}while(user_door > 3 || user_door < 0);
do{
open_door = generator.nextInt(3)+1;
}while(open_door == prize_door || open_door == user_door);

System.out.println(" In a moment, I will show you where the prize is located,");
System.out.println("but first I will show you what is behind one of the other doors");
System.out.println(" Behind door number " + open_door+ " are goats!");
System.out.println("You selected door number " + user_door);
char userReply;
do{
System.out.println(" Would you like to switch your door(y/n)? ");
userReply = scan.next().charAt(0);
}while(userReply!='y' && userReply!='n');   

int user_duplicate = user_door;
if (userReply == 'y') {
do{
user_door = generator.nextInt(3)+1;
}while(user_door == open_door || user_door == user_duplicate);
}

System.out.println("The prize is behind door number: " + prize_door);

if (user_door == prize_door) {
System.out.println("Congratulations! You won the prize!");
} else {
System.out.println("Sorry. You lost.");
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote