You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sjiu/ChallengeTest.java

70 lines
2.6 KiB

/**
* 挑战题测试类
* 测试智能家电接口体系和动态设备管理系统
*/
public class ChallengeTest {
public static void main(String[] args) {
System.out.println("===== 挑战题测试 - 智能家电接口体系和动态设备管理 =====");
// 创建动态设备管理系统
DeviceManager manager = new DeviceManager("Smart Home Manager");
// 创建各种智能家电
Device airConditioner = new SmartAirConditioner("Bedroom AC");
Device livingRoomLight = new SmartLight("Living Room Light");
Device kitchenLight = new SmartLight("Kitchen Light");
Device smartTV = new SmartTV("Living Room TV");
// 添加设备到管理系统
manager.addDevice(airConditioner);
manager.addDevice(livingRoomLight);
manager.addDevice(kitchenLight);
manager.addDevice(smartTV);
// 列出所有设备
manager.listAllDevices();
// 打开所有设备
System.out.println("\n打开所有设备:");
manager.turnOnAllDevices();
// 测试特定功能
System.out.println("\n测试特定设备功能:");
// 测试空调温度调节
if (airConditioner instanceof TemperatureAdjustable) {
TemperatureAdjustable tempDevice = (TemperatureAdjustable) airConditioner;
tempDevice.setTemperature(22);
tempDevice.increaseTemperature(1);
}
// 测试灯光亮度调节
if (livingRoomLight instanceof BrightnessAdjustable) {
BrightnessAdjustable brightDevice = (BrightnessAdjustable) livingRoomLight;
brightDevice.setBrightness(80);
}
// 测试电视的多种功能
if (smartTV instanceof SmartTV) {
SmartTV tv = (SmartTV) smartTV;
tv.play("Netflix - 电影");
tv.setTimer(60);
System.out.println("电视定时器剩余时间: " + tv.getRemainingTime() + " 分钟");
tv.pause();
tv.increaseBrightness(10);
}
// 使用设备管理器的批量功能
System.out.println("\n使用批量管理功能:");
manager.setTemperatureForAll(24); // 设置所有温控设备为24度
manager.setBrightnessForAll(60); // 设置所有灯光为60%亮度
// 列出设备当前状态
System.out.println("\n更新后的设备状态:");
manager.listAllDevices();
// 关闭所有设备
System.out.println("\n关闭所有设备:");
manager.turnOffAllDevices();
}
}