import java.util.Scanner;
class users
{
String username;//用户名
String password;//密码
users(String username,String password)
{
this.username=username;
this.password=password;
}
}
public class LoginDemo {
users user;//设置一个属性
//用户登入方法
public boolean userLogin(String username,String password)
{
if(this.user.username.equals(username)&&this.user.password.equals(password))
{
return true;
}
else
{
return false;
}
}
public void setuser(users user)
{
this.user=user;
}
public static void main(String[] args) {
String username;
String password;
int icount=0;
boolean flag=false;//判断是否登入成功
Scanner in= new Scanner(System.in);
System.out.println("------用户注册-----");
System.out.println("------请输入用户名-----");
username=in.next();
System.out.println("------请输入密码-----");
password=in.next();
users u=new users(username,password);
LoginDemo demo=new LoginDemo();
demo.setuser(u);
System.out.println("------注册成功-----");
System.out.println("------用户登入----");
do{
System.out.println("请输入用户:");
username=in.next();
System.out.println("请输入密码:");
password=in.next();
if(demo.userLogin(username,password))
{
break;
}
else
{
icount++;
if(icount>=3&&flag==false)//如果登入失败超过3次并且
{
System.out.println("------登入失败次数超过三次程序即将推退出----");
System.exit(0);
}
else
{
System.out.println("请检查用户名或者密码");
}
}
}while(true);
System.out.println("登入成功");
}
}
class users
{
String username;//用户名
String password;//密码
users(String username,String password)
{
this.username=username;
this.password=password;
}
}
public class LoginDemo {
users user;//设置一个属性
//用户登入方法
public boolean userLogin(String username,String password)
{
if(this.user.username.equals(username)&&this.user.password.equals(password))
{
return true;
}
else
{
return false;
}
}
public void setuser(users user)
{
this.user=user;
}
public static void main(String[] args) {
String username;
String password;
int icount=0;
boolean flag=false;//判断是否登入成功
Scanner in= new Scanner(System.in);
System.out.println("------用户注册-----");
System.out.println("------请输入用户名-----");
username=in.next();
System.out.println("------请输入密码-----");
password=in.next();
users u=new users(username,password);
LoginDemo demo=new LoginDemo();
demo.setuser(u);
System.out.println("------注册成功-----");
System.out.println("------用户登入----");
do{
System.out.println("请输入用户:");
username=in.next();
System.out.println("请输入密码:");
password=in.next();
if(demo.userLogin(username,password))
{
break;
}
else
{
icount++;
if(icount>=3&&flag==false)//如果登入失败超过3次并且
{
System.out.println("------登入失败次数超过三次程序即将推退出----");
System.exit(0);
}
else
{
System.out.println("请检查用户名或者密码");
}
}
}while(true);
System.out.println("登入成功");
}
}