I am trying to access a boolean variable stay
from my class MontyHall
but cannot because it is non-static and i am trying to access it in a static context
Here is the code:
public void updateStatistics(Door door1, Door door2, Door door3)
{
this.numGames = this.numGames + 1;
oneDoor(door1, 0);
oneDoor(door2, 1);
oneDoor(door3, 2);
if (MontyHall.stay == true){
this.numStay = this.numStay + 1;
}
else{
this.numSwitch = this.numSwitch + 1;
}
}
The variable stay is located in class MontyHall
. Any help would be greatly appreciated as I am very confused how to fix this
Properties of class MontyHall
:
public class MontyHall {
boolean stay;
Door A = new Door("A");
Door B = new Door("B");
Door C = new Door("C");
public MontyHall(Door a, Door b, Door c){
this.A = a;
this.B = b;
this.C = c;
}}