package cn.itcast;
import java.util.Scanner;
public class HomeWork1 {
private String userName = "shuijw";
private String passWord = "123456";
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassWord() {
return passWord;
}
public void setPassWord(String passWord) {
this.passWord = passWord;
}
public boolean compare(String userName,String passWord)
{
return this.userName==userName&&this.passWord==passWord;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
for (int i = 0; i < 3; i++) {
System.out.println("请输入账号:");
String s = sc.nextLine();
System.out.println("请输入密码:");
String c = sc.nextLine();
HomeWork1 h = new HomeWork1();
if(s.isEmpty()||c.isEmpty())
{
System.out.println("账号或密码不能为空");
System.out.println("你还有"+(2-i)+"次机会");
continue;
}
if(h.compare(s,c))
{
System.out.println("登录成功");
}
else
{
if(i<2)
{
System.out.println("账号或密码错误,请重新输入");
System.out.println("你还有"+(2-i)+"次机会");
}
else
System.out.println("登录失败,账号锁定");
}
}
}
}
|
|