「O」でランプレベルを表示するプログラムを書いていますが、コンパイルすると「シンボルが見つかりません」と表示され、「メッセージ」と「明るさ」を宣言しています。class Lamp と class 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);
}
}