我正在编写一个程序以“O”显示灯的级别,但是当我编译时,它显示“找不到符号”,我已经声明了“消息”和“亮度”,还有什么我想声明的吗?类 Lamp 和类 TestLamp 我保存在不同的文件中,当我编译 Lamp 时,它没有显示错误。但是编译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);
}
}