登陆验证Demo

登录验证,当用户名为abc,密码为123时返回通过,否则为登录失败,若只输入了其中一项,则返回参数不正确。

代码如下:

//登录验证范例 ——一个标准的程序设计模式

class Login

{

private String name;

private String password;

public Login(String name,String password)

{

this.name=name;

this.password=password;

voildate();

}

private void voildate()

{

if(name.equals("abc")&&password.equals("123"))

{

System.out.println("登录成功");

}

else

{

System.out.println("登录失败");

}

}

};

class Controll

{

private String args[];

public Controll(String args[]) //接受参数

{

this.args=args;

info();

}

private void info()

{

if(args.length!=2)

{

System.out.println("输入的参数不正确");

System.exit(1);

}

new Login(this.args[0],this.args[1]); //传递参数到验证类

}

};

public class JavaDemo15

{

public static void main(String args[])

{

new Controll(args);

}

};

运行结果:

你可能感兴趣的:(设计模式)