0
light bulb on and off
to make a program class with a bulb.to turn on and off. i an using boolean, but how do you output to false to off and on to true?
4 Réponses
+ 1
You can either create two booleans named off and on. Or if you're just trying to get the System.out.println to say off and on, and you created a bulb class with isOn boolean variable, do something like
if(myBulb.isOn)
System.out.println( The bulb is on);
else
System.out.println(The bulb is off);
Can't see your code so not exactly sure what you are trying to do, hope this helps
0
this is what i have:
public class bulb
{
private boolean state;
public bulb()
{
state = false;
}
public void turnOn()
{
state = true;
}
public void turnOff()
{
state = false;
{
public String toString()
{
return "Bulb is" + state;
}
}
0
im trying to make a driver and instantiate objects with on and off, but not sure if i am in right path
0
Sorry, I want to help you. but you're not making much sense on what it is you're actually trying to do. Instantiate means to create an object, if you want an object created depending on off or on, you just create an if statement.
if(isOn)
Object obj = new Object();
Since I don't think that's what you actually mean, you'll need to clarify a bit more