To view the source of the Java SE source files directly, either download the
source code off the Internet or visit JDocs at http://www.jdocs.com/. JDocs
provides an interface to the source code of several Java-based projects,
including the Java platform, Standard Edition.
ealier i was using assignment operator which changed the value toif (on == true)
instead of comparing it .true
with brackets which works more appropriately.if (( volume == 1) && (volume == 100))
Joel Christophel wrote:Look at your brackets for your getChannel() method. The first one is misplaced.
Also, your switchTvOn() method has some problems.
1. It's return type is int, but you're returning a boolean.
2. Why isn't the return type void? You're not getting the TV's state, you're setting it.
3. Calling switchTvOn(false) should turn the TV off, and switchTvOn(true) should turn it on, but you're just setting things to true.
4. Also, you have two on variables, a local method variable and a state variable. When you do on = true; you're setting the local variable to true instead of the state variable.
Here's how switchTvOn() should look:
In the above, this.on refers to the on state variable at the top of your class, and on refers to the local on variable that was passed in to the method. All you're doing is setting the your TV on or off, depending on whatever boolean value the user passes in.
One more thing:
You should read up on access modifiers. Basically, classes, class variables, methods, and more can all be labeled with an access modifier (e.g. public, private, protected). When using ClassA from ClassB, ClassA's access modifiers will either block or allow the visibility of its various components. As a rule of thumb for now:
1. Classes should be public (e.g. public class Tester{})
2. If methods and variables are only to be used within the class they're declared in, make them private.
3. If methods and variables are to be used from other classes, make them public.
Cheers!