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

Your program should run a Door Prize game. In the game, there are three doors (A

ID: 3722881 • Letter: Y

Question

Your program should run a Door Prize game. In the game, there are three doors (A, B, and C) and the contestant gets two guesses. After the contestant guesses the first time, the host (who knows the door that has the prize behind it) reveals one of the doors that does NOT contain the prize. The door that the host reveals is never the same as the one the contestant guesses.

Then, the contestant has a second guess. They may choose the same door as they did the first time, or they can choose a different door. This second guess is their final guess. After they make their second guess, the host reveals whether they have won or lost the prize.

In our computer version of the game, we will give the user prompts to guess their door. After the guess, the revealed door is displayed. Then, the user makes a second guess. The game reveals if the second guess is the winner. Then, the user is given the option if they want to play again.

With each input (including door guesses and whether or not they want to play again), the program should validate the user input. That is, if the user enters any input characters that are NOT among the options, they are given an error and asked for that input again. See the following example of how the program may work:

Which door do you choose? (A/B/C) A It is not behind door B Which door do you choose? (A/B/C) C You won! Play again? (Y/N) E E is not a valid response. Please choose from (Y/N) Play again? (Y/N) y Which door do you choose? (A/B/C) b It is not behind door C Which door do you choose? (A/B/C) b You lose. Play again? (Y/N)Y Which door do you choose? (A/B/C) a It is not behind door B Which door do you choose? (A/B/C) F F is not a valid door. Please choose from (A/B/C. which door do you choose? (A/B/C) a You lose. Play again? (Y/N) n

Explanation / Answer

//implemented in java language

import java.util.*;
public class Montey_hall {
public static void main(String args[])
{ Scanner sc=new Scanner(System.in);

char option='y';
  
  
while(option=='Y' || option == 'y')
{
int arr[]={0,0,0,0};
int position_win=(int)(Math.random()*(3-1)+1);
arr[position_win]=1;
char ch='1';int choice=-1;
  
while(ch!='A' && ch!='B'&& ch!='C' && ch!='a' && ch!='b' && ch!='c' )
{System.out.print("which door do you choose? (A/B/C):");
ch=sc.nextLine().charAt(0);
System.out.println(ch);
if(ch=='A' || ch=='a')
choice=1;
else if(ch== 'B' || ch=='b')
choice=2;
else if(ch== 'C' || ch=='c')
choice=3;
else
System.out.println(ch+" is not a valid door. please choose (A/B/C)");
}
if(choice==1)
{if(arr[2]==0)
System.out.println("It is not behind B");
else
System.out.println("It is not behind C");
System.out.println("which door you choose now (A/B/C)");
ch=sc.nextLine().charAt(0);
if(ch=='b' || ch=='B')
choice=2;
else if(ch=='c' || ch=='C')
choice=3;
else if(ch=='A'|| ch=='a')
choice=1;
else
System.out.println("there is no door"+ch+" , you loose");
if(arr[choice]==1)
System.out.println("you win !!!");
else
System.out.println("you loose");
}
  
else if(choice==2)
{if(arr[1]==0)
System.out.println("It is not behind A");
else
System.out.println("It is not behind C");
System.out.println("which door you choose now (A/B/C)");
ch=sc.nextLine().charAt(0);
if(ch=='A' || ch=='a')
choice=1;
else if(ch=='c' || ch=='C')
choice=3;
else if(ch=='b' || ch=='B')
choice=2;
else
System.out.println("there is no door"+ch+" , you loose");
if(arr[choice]==1)
System.out.println("you win !!!");
else
System.out.println("you loose");
}
  
else if(choice==3)
{if(arr[1]==0)
System.out.println("It is not behind A");
else
System.out.println("It is not behind B");
System.out.println("which door you choose now (A/B/C)");
ch=sc.nextLine().charAt(0);
if(ch=='A' || ch=='a')
choice=1;
else if(ch=='c' || ch=='C')
choice=3;
else if(ch=='b' || ch=='B')
choice=2;
else
System.out.println("there is no door, "+ch+" you loose");
if(arr[choice]==1)
System.out.println("you win !!!");
else
System.out.println("you loose");
}
System.out.println("Do you want play new game (Y/N):");
option=sc.nextLine().charAt(0);
while(option !='Y'&&option !='y' &&option != 'n' && option !='N')
{ System.out.println("you entered "+option+" please Enter (Y/N):");
option=sc.nextLine().charAt(0);
}
}  
}

}