I am writing a program to show the lamp level with "O", but when I compile, it show "cannot find symbol", I have declare "message" and "brightness", Is there anything else I miss to declare? class Lamp and class TestLamp I save in different file, when I compile Lamp ,It show no error. But it show "cannot find symbol" when compiling TestLamp
class Lamp {
// Sub-task 1: Declare and initialize data member with default value
int brightness=1;
// Sub-task 2: Define a method to indicate the brightness level of lamp
String getBrightness() {
String message = "";
while(brightness>0) {
brightness--;
message += "O";
}
return message;
}
// Sub-task 3: Define a method to update the brightness of the lamp
void setBrightness(int b) {
if(b<1 || b>5)
brightness=2;
else
brightness=b;
}
}
class TestLamp {
public static void main (String[] args) {
// Sub-task 4: Declare and create 3 lamp objects
Lamp lamp1,lamp2,lamp3;
// Sub-task 5: Adjust the lamp brightness according to the requirement
lamp1.setBrightness(3);
lamp2.setBrightness(10);
// Sub-task 6: Display the information of the created lamps
lamp1.getBrightness();
System.out.println("Lamp1"+lamp1.message);
lamp2.getBrightness();
System.out.println("Lamp2"+lamp2.message);
}
}
TestLampis not in the same package, you must putimport package.Lampbefore your class declaration.