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.

54 lines
2.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/**
* 进阶题测试类
* 测试安全设备接口体系Lockable、Monitored、Alarmable
*/
public class AdvancedTest {
public static void main(String[] args) {
System.out.println("===== 进阶题测试 - 安全设备接口体系 =====");
// 创建智能门锁只实现Lockable接口
Lockable doorLock = new SmartDoorLock("Front Door Lock");
// 创建智能摄像头实现Monitored和Alarmable接口
SmartCamera camera = new SmartCamera("Living Room Camera");
// 创建家庭安全系统(实现所有三个接口)
HomeSecuritySystem securitySystem = new HomeSecuritySystem("Main Security System");
// 测试智能门锁
System.out.println("\n测试智能门锁只实现Lockable接口:");
testLockable(doorLock);
// 测试智能摄像头
System.out.println("\n测试智能摄像头实现Monitored和Alarmable接口:");
testMonitored(camera);
camera.detectMotion(); // 测试运动检测触发警报
testAlarmable(camera);
// 测试家庭安全系统
System.out.println("\n测试家庭安全系统实现所有三个接口:");
securitySystem.activateFullSecurity();
System.out.println(securitySystem.getMonitoringStatus());
securitySystem.triggerAlarm();
securitySystem.silenceAlarm();
}
private static void testLockable(Lockable device) {
System.out.println("初始锁定状态: " + device.isLocked());
device.unlock();
System.out.println("解锁后状态: " + device.isLocked());
device.lock();
System.out.println("重新锁定后状态: " + device.isLocked());
}
private static void testMonitored(Monitored device) {
device.startMonitoring();
System.out.println(device.getMonitoringStatus());
}
private static void testAlarmable(Alarmable device) {
System.out.println("警报状态: " + device.isAlarmTriggered());
device.silenceAlarm();
System.out.println("解除警报后: " + device.isAlarmTriggered());
}
}