mirror of
https://github.com/Dichgrem/Java.git
synced 2025-12-17 04:51:58 -05:00
update:demo4
This commit is contained in:
31
com/study/demo4/TestControl.java
Normal file
31
com/study/demo4/TestControl.java
Normal 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"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user