//门禁系统类
public abstract class ControlSys {
public Door door; // 门禁系统的电子门
public Computer computer; // 门禁系统的计算机
public InputEquip inputEquip; // 门禁系统的输入设备
public int ring; // 门铃,0为安静,1为鸣响
public static int openSign; // 开门信号,由管理员按下按钮时产生
public void work() {//工作方法
}
}
//门禁系统输入设备
package Doorsystem.system;
import java.util.Scanner;
import Doorsystem.checking.Realize;
public class InputEquip extends ControlSys {// 门禁系统的输入设备
public static String input = null;
public static boolean isok;
@Override
public void work() {
Scanner inputs = new Scanner(System.in);
Realize r=new Realize();
System.out.print("———欢迎使用XXX公司的验证系统———\n请选择类型(1:输入密码 2:按门铃):");
int num= inputs.nextInt();
if (num==1) {
System.out.print("请选择验证方式(1:输入密码 2:胸卡 3:指纹 4:设置密码):"+
"\n密码以“pa”开头! 胸卡以“ca”开头! 指纹以“fi”开头");
int num1= inputs.nextInt();
switch (num1) {
case 1:
System.out.print("请输入密码:");
input= inputs.next();
String n= input.substring(0,2);
if (n.equals("pa")) {
input= input.substring(2);
isok=r.checkingpwd(input);
}
else {
System.out.println("密码错误!");
}
break;
case 2:
System.out.print("请输入胸卡密码:");
input= inputs.next();
String n1= input.substring(0,2);
if (n1.equals("ca")) {
input= input.substring(2);
isok=r.checkingca(input);
}
else {
System.out.println("密码错误!");
}
break;
case 3:
System.out.print("请输入指纹密码:");
input= inputs.next();
String n2= input.substring(0,2);
if (n2.equals("fi")) {
input= input.substring(2);
isok=r.checkingfi(input);
}
else {
System.out.println("密码错误!");
}
break;
case 4:
System.out.println("原密码:");
input= inputs.next();
String a= input.substring(2);
System.out.println("新密码:");
input= inputs.next();
String a1= input.substring(2);
if (r.checkingchang(a, a1)) {
System.out.println("修改成功!");
this.work();
}
break;
default:
System.out.println("请输入正确指令!");
break;
}
}
else if(num==2) {
ring=1;
System.out.print("管理员(XXX)门铃响了是否同意开门(1:同意 2:不同意):");
openSign= inputs.nextInt();
}
else {
System.out.println("请输入正确指令!");
}
}
}
//验证密码接口
package Doorsystem.checking;
public interface Checking {
boolean checkingca(String n);
boolean checkingfi(String n);
boolean checkingpwd(String n);
int checkingring(int n);
boolean checkingchang(String n,String n1);
}
//验证密码接口实现
package Doorsystem.checking;
import Doorsystem.system.InputEquip;
public class Realize extends InputEquip implements Checking {
public static String[] inner=new String[5];
public void show(){//初始化密码
if (inner[0]==null) {
inner[0]="111";
}
System.out.println(inner[0]);
if (inner[1]==null) {
inner[1]="222";
}if (inner[2]==null) {
inner[2]="333";
}
}
@Override
public boolean checkingpwd(String n) {//密码验证
show();
for (int i = 0; i < inner.length; i++) {
if (n.equals(inner[i])) {
return true;
}
}
return false;
}
@Override
public boolean checkingca(String n) {//胸卡验证
show();
for (int i = 0; i < inner.length; i++) {
if (n.equals(inner[i])) {
return true;
}
}
return false;
}
@Override
public boolean checkingfi(String n) {//指纹验证
show();
for (int i = 0; i < inner.length; i++) {
if (n.equals(inner[i])) {
return true;
}
}
return false;
}
@Override
public int checkingring(int n) {//门铃验证
if (n==1) {
System.out.println("门铃以响");
}
return n;
}
@Override
public boolean checkingchang(String n,String n1) {//修改密码验证
this.show();
for (int i = 0; i < inner.length; i++) {
System.out.println(inner[i]);
if (n.equals(inner[i])) {
inner[i]=n1;
return true;
}
}
return false;
}
}
// 门禁系统的电子门
package Doorsystem.system;
import java.util.Timer;
import java.util.TimerTask;
public class Door {// 门禁系统的电子门
private static int i=5;
public void work(){
System.out.println("验证通过!门已开\n欢迎光临!");
final Timer time=new Timer();
time.schedule(new TimerTask() {
@Override
public void run() {
if (i!=0) {
i--;
System.out.println("还剩"+i+"秒,请尽快通过");
}
else{
System.out.println("时间到!门已关");
i=5;
InputEquip c=new InputEquip();
c.work();
}
}
}, 0,500);
}
}
// 门禁系统的计算机
package Doorsystem.system;
public class Computer extends ControlSys {
Door d=new Door();
@Override
public void work(){
if (inputEquip.isok) {//密码验证通过否
d.work();
}
if(openSign==1){//管理员同意否
d.work();
}
}
}
//测试类
package Doorsystem.checking;
import Doorsystem.system.Computer;
import Doorsystem.system.InputEquip;
public class Text {
public static void main(String[] args) {
InputEquip c=new InputEquip();
c.work();
Computer c1=new Computer();
c1.work();
}
}