luboldja
11-12-2009, 03:21 AM
Yea, im making a small java driving game for my school, and it is INSANELY simple, but this line of code is giving me hell a dificulty. Can anyone tell me why it like... doesn't work, i'll paste my whole class in here if u need more, but its just this method im having trouble with.
public void drive(double distance){
if(gas > 0){
if(isCarStarted = true){
gas = gas - (distance/efficiency);
System.out.println("You have driven " + distance + " miles. You have " + gas + " gallons of gas left.");
}else{
System.out.println("You cannot drive.");
}
}
}
I dont know why it won't print "You cannot drive." to the screen when gas is not greater than 0 OR isCarStarted = false. Can anyone help?
public void drive(double distance){
if(gas > 0){
if(isCarStarted = true){
gas = gas - (distance/efficiency);
System.out.println("You have driven " + distance + " miles. You have " + gas + " gallons of gas left.");
}else{
System.out.println("You cannot drive.");
}
}
}
I dont know why it won't print "You cannot drive." to the screen when gas is not greater than 0 OR isCarStarted = false. Can anyone help?