期末作业!
名为Main的类,点击查看代码
public class Main {
public static void main(String[] args) {
System.out.println("***测试中国空调***");
ChineseAirConditioner conditioner1 = new ChineseAirConditioner();
conditioner1.startUp();//启动
conditioner1.displayStatus();//=> 空调状态:启动
conditioner1.shutDown();
conditioner1.displayStatus();// => 空调状态: 关闭
System.out.println("***测试美国空调***");
AmericanAirConditioner conditioner2 = new AmericanAirConditioner();
conditioner2.startUp();
conditioner2.displayStatus();
conditioner2.shutDown();
conditioner2.displayStatus();
}
}
名为ChineseAirConditioner的类,点击查看代码
public class ChineseAirConditioner {
private boolean kai;//kai是一个变量
public void startUp() {
kai = true;
}
public void shutDown() {
kai = false;
}
public void displayStatus() {
if(kai){
System.out.println("空调状态:开启");
}else {
System.out.println("空调状态:关闭");
}
}
}
名为AmericanAirConditioner的类,点击查看代码
public class AmericanAirConditioner {
private boolean kai;//这里的kai和前面的kai不一样
public void startUp() {
kai = true;
}
public void shutDown() {
kai =false;
}
public void displayStatus() {
if(kai){
System.out.println("Air Conditioner Status: ON");
}else {
System.out.println("Air Conditioner Status: OFF");
}
}
}
进程已结束,退出代码为 0