update:demo4

This commit is contained in:
dichgrem
2025-11-28 16:59:17 +08:00
parent 41e6b71bd7
commit 5832b4fe9d
34 changed files with 307 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
package com.study.demo4;
import java.util.ArrayList;
import java.util.List;
public class TestControl {
public static void main(String[] args) {
HomeController controller = new HomeController();
// 创建设备
SmartLight light = new SmartLight("Living Room Light");
SmartAirConditioner ac = new SmartAirConditioner("Bedroom AC");
SmartMasher masher = new SmartMasher("Kitchen Masher");
// 添加到控制器
controller.addDevice(light);
controller.addDevice(ac);
controller.addDevice(masher);
// 测试设备状态
light.turnOff();
ac.turnOff();
masher.turnOn();
// 查询状态
System.out.println(controller.getDeviceStatus("Living Room Light"));
System.out.println(controller.getDeviceStatus("Bedroom AC"));
System.out.println(controller.getDeviceStatus("Kitchen Masher"));
System.out.println(controller.getDeviceStatus("Non-existent Device"));
}
}