forked from sourabh48/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCarGoatSim.java
More file actions
88 lines (65 loc) · 2.2 KB
/
CarGoatSim.java
File metadata and controls
88 lines (65 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import java.io.*;
public class CarGoatSim
{
public static void main(String[] Args) throws IOException
{
int change=0;
int Wins=0;
int Lose=0;
int Counter=0;
int CarDoor=0;
int [] Door = new int[3];
int Guess=0;
int OpenedDoor=0;
boolean CHANGE_DOOR=false;
for (int p=0; p<2; p++){
if (change==1){
System.out.println("Changing Door Results Below");
CHANGE_DOOR=true;
Wins=0;
Lose=0;
}
change++;
for (int i=0; i<10000; i++)
{
Door[0]=0;
Door[1]=0;
Door[2]=0;
CarDoor = (int)((Math.random()*9)%3);
Door[CarDoor]=1;
Guess = (int)((Math.random()*9)%3);
OpenedDoor = FindGoat(Door,Guess);
Door[OpenedDoor]=-1;
if (CHANGE_DOOR){
for (int j=0; j<3; j++){
if (Door[j] != -1 && Door[j] != Guess){
Guess=j;
}
}
}
if (Door[Guess]==1){
Wins++;
}
else{
Lose++;
}
}
System.out.println(Wins + " Wins and " + Lose + " Loses ");
}
}
public static int FindGoat(int[] Door,int Guess)
{
int GoatDoor=0;
int TryDoor=0;
boolean Found=false;
while(!Found)
{
TryDoor = (int)((Math.random()*9)%3);
if (Door[TryDoor]==0){
GoatDoor=TryDoor;
Found=true;
}
}
return GoatDoor;
}
}