mirror of
https://github.com/Dichgrem/Java.git
synced 2025-12-16 12:41:58 -05:00
32 lines
933 B
Java
32 lines
933 B
Java
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"));
|
|
}
|
|
}
|