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.

50 lines
1.1 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接口专注于锁定功能
*/
public class SmartDoor implements Lockable {
private String name;
private boolean locked;
/**
* 构造函数
* @param name 智能门锁名称
*/
public SmartDoor(String name) {
this.name = name;
this.locked = false; // 默认解锁状态
}
@Override
public void lock() {
if (!locked) {
locked = true;
System.out.println(name + " 已锁定");
} else {
System.out.println(name + " 已经是锁定状态");
}
}
@Override
public void unlock() {
if (locked) {
locked = false;
System.out.println(name + " 已解锁");
} else {
System.out.println(name + " 已经是解锁状态");
}
}
@Override
public boolean isLocked() {
return locked;
}
/**
* 获取智能门锁名称
* @return 智能门锁名称
*/
public String getName() {
return name;
}
}