Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Public Boolean on; public Light Bulb () {on = False;} public void change() {on =

ID: 3816310 • Letter: P

Question

Public Boolean on; public Light Bulb () {on = False;} public void change() {on = ion;} public Boolean isOn() {return on;} public String toString() {String result = "Light is"; if(on) return result + "on" else return result + "off"} public static void main (String [] args) {LightBulb.change();//a LightBulb 1t = new LightBulb(40)l//b LightBulb b1b = new LightBulb();//c System.out.println(b1b);//d on = b1b.isOn();//e if(b1b.isOn == true)//f change();//g else if (isOff(b1b))//h System.out.println(b1b.change());//i LightBulb = b1b.change();//j}}

Explanation / Answer

a. LightBulb.change(); - It's not right. What it's trying to do is to call a method without creating a LightBulb object. Since the method change() is not static, it's not valid. Static methods can be invoked without an object, ie, directly with a class.

b. LightBuld lt = new LightBulb(40); - This is not valid since LightBulb doesn't have a constructor which takes a parameter as an argument. The only constructor it has takes no arguments. Constructor is the one which goes like this, in your case:

public LightBuilb() {

on = false;

}

c. valid.

d. valid.

e. Not valid. There is no variable decalred by the name 'on' in your main method. Always declare a variable before using.

f. Not valid. For a LightBulb object, there's no attribute by the name 'isOn'. What you're trying to do is to call the method 'isOn()'. It needs a parentheses. Another problem is, there's no '{' after if the statement.

g. Not valid. You need to call the method 'change()' on a LightBulb object. Like, blb.change() but not directly.

h. Not valid. There's no method by the name 'isOff(LightBulb b)' for LightBulb and '{' too.

i. Not valid. The change() method returns nothing.

j. Not valid. First of all, you don't have a variable name, you just have the type there (LightBulb). Secondly, blb.change() returns nothing.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote