I'm getting things going with classes, but, if you run this code, my print statement still shows "aV1.on" as "true", though "turnOff" has been activated. If I change line 5 to "turnOn", it also shows as "true". Are the other two reference variables in Main causing any conflict? I would expect "on" to reflect any toggling that's done.
What's the problem, here?Code:
public class VariousPractice {
public static void main(String[] args) {
Stereo aV1 = new Stereo();
aV1.turnOff();
aV1.adjStation(1200);
aV1.adjVolume(17);
System.out.println("aV1's power is now " + aV1.on + ", it's station is set to "
+ aV1.rStation + ", and the volume is set to " + aV1.rVolume + ".");
}
}
class Stereo {
boolean on = false;
int rStation = 1;
int rVolume = 1;
Stereo() {
}
public void turnOn() {
on = true;
}
public void turnOff() {
on = false;
}
public void adjStation(int newStation) {
if (on = true && newStation >= 700 && newStation <= 1400)
rStation = newStation;
}
public void adjVolume(int newVolume) {
if (on = true && newVolume >= 1 && newVolume <= 20)
rVolume = newVolume;
}
}
Edit: If I set "adjVolume" and "adjStation" to a number outside of their respective boundaries, "on" finally gets set to "false". It remains "false" even if I set it back to "turnOn".

