import java.util.Scanner;

public class Login {
    private String username;
    private String password;


    public boolean login(Scanner s) {
        System.out.println("用户操作登录功能");
        if (this.username == null || this.password == null){
            System.out.println("用户还未注册,请先注册..");
            return false;
        }
        System.out.print("请输入账号:");
        String usernaem = s.next();
        System.out.print("请输入密码:");
        String password = s.next();
        if (this.username.equals(usernaem) && this.password.equals(password)){
            System.out.println("恭喜您,登录成功...");
            return true;
        }else {
            System.out.println("抱歉登录失败!!!");
        }
        return false;
    }
    public void register(Scanner s){
        System.out.println("用户操作注册功能");
        System.out.print("请输入账号:");
        this.username = s.next();
        System.out.print("请输入密码:");
        this.password = s.next();
    }

    public void show(){
        System.out.println("查看账户功能");
        System.out.println("账号:"+this.username+"密码:"+this.password);
    }

    public void sigOut(){
        System.out.println("用户操作查看功能");
        System.out.println(this.username+"再见了您嘞");
    }


    public static void main(String[] args){
        Login login = new Login();
        Scanner s = new Scanner(System.in);
        while (true){
            System.out.println("请用户选择需要操作的类型 1.登录 2.注册 3.查看 4.退出");
            System.out.println("请输入您的操作类型:");
            int type = s.nextInt();
            if (type == Login.TYPE_1){
                boolean flog = login.login(s);
                if (flog){
                    break;
                }
            }else if (type == Login.TYPE_2){
                login.register(s);
            }else if (type == Login.TYPE_3){
                login.show();
            }else if (type == Login.TYPE_4){
                login.sigOut();
            }else {
                System.out.println("用户操作类型输入错误,请重新输入");
                continue;
            }
        }
    }

    public static final int TYPE_1 = 1;
    public static final int TYPE_2 = 2;
    public static final int TYPE_3 = 3; 
    public static final int TYPE_4 = 4;

}
最后修改:2021 年 05 月 30 日
如果觉得我的文章对你有用,请随意赞赏