Why wont my boolean variable change?
Hello I'm making a calculater and I have some problem with my booleans.
When I press a number the boolean 'opera' should be set to true so that my program can register if I press +,- or *. But there is a problem, the code in getNrAction will run and register and print the first number i press, but the boolean wont change to true. Anyone have any ideas of what is wrong?
Code:
public class Calculate
{
private String _operator;
private String _nr;
private String _equal;
private int frtInt;
private int scdInt;
boolean frtNr = true;
boolean scdNr = false;
boolean opera = false;
public Calculate()
{
}
//when '*', '/'or '+' is pressed
public void getOperAction(String text)
{
if (opera == true)
{
_operator = text;
scdNr = true;
opera = false;
System.out.println(_operator);
}
if(opera == false)
System.out.println("FAILURE TEST");
}
// when a number-button is pressed
public void getNrAction(String text)
{
_nr = text;
int intNr = Integer.parseInt(_nr);
if(frtNr == true )
{
frtInt = intNr;
System.out.println(frtInt);
opera = true;
frtNr = false;
}
if (scdNr == true)
{
scdInt = intNr;
System.out.println(scdNr);
}
}
// when '='-button is pressed
public void getEqualAction(String text)
{
_equal = text;
System.out.println(_equal);
}
// public String giveNrError()
// {
// return errorNr;
// }
}