简单的注册登录系统

代码:(三部分:Sx.java -> Student_control.java -> startl.java)*****************************Sx.java****************************
package com.qsy.student.sx;
public class Sx {
    private int ID;
    private String name;
    private int age;
    private String sex;
    private String school;
    public int getID() {
        return ID;
    }
    public void setID(int ID) {
        this.ID=ID;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name=name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age=age;
    }
    public String getSex() {
        return sex;
    }
    public void setSex(String sex) {
        this.sex=sex;
    }
    public String getSchool() {
        return school;
    }
    public void setSchool(String school) {
        this.school=school;
    }
}
************************start.java*******************************
package com.qsy.student.start;

import com.qsy.student.control.Student_control;

import java.util.Scanner;

public class Start {
    public static void main(String[] args) {
        Student_control iss=new Student_control();
        System.out.println("————————学生信息管理系统—————————");
        System.out.println("——————————1.注册————————————");
        System.out.println("——————————2.登录————————————");
        System.out.println("——————————3.退出————————————");
        new Start().sta();
    }
    public void sta(){
        Student_control iss=new Student_control();
        while (true){
        System.out.println("您想要做什么操作...");
        Scanner ins=new Scanner(System.in);
        NNT:
        while(true){
        int no=ins.nextInt();
            if (no==1){
                System.out.println("注册Y/N");
                String fen=ins.next();
                while ("Y".equals(fen)){
                    iss.shuzu();
                    System.out.println("您还需要添加学生信息吗?Y/N");
                    fen = ins.next();
                }

               break;
            }else if (no==2){
                System.out.println("登录");
                iss.login();
                break ;
            }else if (no==3){
                System.out.println("谢谢使用...祝您生活愉快!");
                break ;
            }else{
                System.out.println("无此选项,请重新选择...");
            }
        }
        }
    }
}
************************Student_control.java**********************
package com.qsy.student.control;
import com.qsy.student.sx.Sx;
import java.util.Scanner;
public class Student_control {
    Sx isx = new Sx();
    private int i;
    Sx student[] = new Sx[10];
    //Sx cfstudent[] = new Sx[10];
    Scanner ins=new Scanner(System.in);
    public static void main(String[] args) {
    }
    //对象数组登录注册
    public Sx[] shuzu() {

        //student[i]=new Sx(1,"nn",3,"nv","sss");
        //int i=0;//每一次调用i都会是1
        student[i]=new Sx();

        System.out.println("请输入ID:");
        student[i].setID(ins.nextInt());
        //System.out.println("ID为:");

        System.out.println("请输入name:");
        student[i].setName(ins.next());
        //System.out.println("name为:");

        System.out.println("请输入age:");
        student[i].setAge(ins.nextInt());
        //System.out.println("age为:");

        System.out.println("请输入sex:");
        student[i].setSex(ins.next());
        //System.out.println("sex为:");

        System.out.println("请输入school:");
        student[i].setSchool(ins.next());
        //System.out.println("school为:");

        i++;
        return this.student;
    }
    public void login(){

        Scanner ins=new Scanner(System.in);
        OUT:
        while(true){
            //student[0]=new Sx(1,"nn",3,"nv","sss");

            System.out.println("请输入想要查询name:");
            String rr=ins.next();
            System.out.println("请输入密碼:");
            int mm=ins.nextInt();
            if (rr!=null){
                //boolean yes=false;
                for (int j=0; j <this.student.length ; j++) {
                    if (this.student[j]!=null){
                        if (rr.equals(this.student[j].getName())&& mm==123){
                            System.out.println("祝贺你!登录成功");
                            //yes=true;
                            break OUT;
                        }
                    }
                    }
                        System.out.println("查无此人");
            }
            else{
                System.out.println("还要进行下面操作么?进行Y,不进行N");
                String aa=ins.next();
                if ("Y".equals(aa))
                {System.out.println("请重新输入name与密码");}
                else if ("N".equals(aa)){
                    break OUT;
                }else{
                    System.out.println("输入错误");
                    break OUT;
                }
            }
        }
    }
}

 

posted on 2019-08-02 20:51  年夜饭  阅读(629)  评论(0编辑  收藏  举报

导航