- May 9, 2005
- 2,044
- 1
- 81
I got part A and B done, but I can't seem to figure out part C.
Part C:
The programmer who wrote the Lamp class (below) was a bit of a "dim" bulb and didn't complete the class definition. Your job is to add the missing code so that the Lab24C "tester" class will run to display the following:
There is darkness...
There is light...
Do NOT change any existing code.
Part C:
The programmer who wrote the Lamp class (below) was a bit of a "dim" bulb and didn't complete the class definition. Your job is to add the missing code so that the Lab24C "tester" class will run to display the following:
There is darkness...
There is light...
Do NOT change any existing code.
Code:
public class Lab24C {
public static void main(String[] args) {
Lamp myLamp = new Lamp();
System.out.println(myLamp.toString());
myLamp.setIsOn(true);
System.out.println(myLamp.toString());
}
}
class Lamp {
private boolean hasBulb;
private boolean isOn;
// YOUR CODE GOES HERE
public void setHasBulb(boolean parm) {
hasBulb = parm;
}
public void setIsOn(boolean parm) {
isOn = parm;
}
public String toString() {
if (hasBulb && isOn) {
return "There is light...";
}
else {
return "There is darkness...";
}
}
}
