|
|
/**
|
|
|
* 进阶题测试类
|
|
|
* 测试安全设备接口体系(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());
|
|
|
}
|
|
|
} |