2 qiu7qiu7 qiu7qiu7 于 2016.05.05 17:26 提问

求帮助,java程序运行一半运行不下去了
 public class main {
    public static void main(String[] args){
        Index ui = new Index();
        ui.index();
    }
}
 import java.util.Scanner;

public class Index {
    Scanner scanner = new Scanner(System.in);
    management management = new management();

    void index(){
            System.out.println("----------------学生管理系统------------------");
            System.out.println("1.学生注册");
            System.out.println("2.学生注销");
            System.out.println("3.查阅学生信息");
            System.out.println("4.列出所有学生信息");
            System.out.println("5.退出");
            System.out.println("-----------------------------------------");
            System.out.println("请输入1-5:");
            int select = 0;
            select = scanner.nextInt();
            select(select);
    }

    void select(int n){
        switch(n){
        case 1:
            register();
            break;
        case 2:
            cancel();
            break;
        case 3:
            check_one();
             break;
        case 4:
            check_all();
            break;
        case 5:
            exit();
            break;
        default:
            break;
        }
    }

    private void register() {
        String name = "";
        String department="";
        System.out.println("学生管理>>新生注册");
        while (true){
            System.out.println("请输入学生姓名:");
            name = scanner.next();

            System.out.println("请输入院系名称:");
            department = scanner.next();

            boolean result=management.regisStudent(name, department);
            if(result == true){
                System.out.println("注册成功。");
            }
            else{
                System.out.println("注册失败。");
            }

            System.out.println("输入y继续,输入n返回主菜单");
            String input = scanner.next();
            if(input.equalsIgnoreCase("n")){
                return;
            }
        }
    }

    void cancel(){
        System.out.println("学生管理>>学生注销");

        while(true){
            System.out.println("请输入学生编号:");
            int num=scanner.nextInt();

            boolean temp=management.unregisStudent(num);
                    if(temp){
                        System.out.println("注销成功");
                    }
                    else{
                        System.out.println("注销失败");
                    }

                    System.out.println("输入y继续,输入n返回主菜单");
                    if(scanner.next().equalsIgnoreCase("n"))
                        return;
        }
    }

    void check_all(){
        while(true){
            System.out.println(management.getAllStudentsInfo());
            System.out.println("输入y刷新,输入n返回主菜单:");
            if(scanner.next().equalsIgnoreCase("n"))
                return;
        }   
    }

    void check_one(){
        while(true){
            int num = 0;
            System.out.println("请输入要查询的学生编号:");
            management.getStudentInfo(num);
            if(scanner.next().equalsIgnoreCase("n"))
                return;
        }
    }

    void exit(){
        return;
    }
}


public class Student {
    private static int sid=1;
    private int id;
    private String name;
    private String department;


    public Student(String name, String department) {
        if(name.equals("")||department.equals(""))
            return;
        this.name = name;
        this.department = department;
        id=sid++;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDepartment() {
        return department;
    }

    public void setDepartment(String department) {
        this.department = department;
    }

    public int getId() {
        return id;
    }
}


public class DataBase {
    Student[] student_database = new Student[100];
    private int point = 0;

    boolean push_new_student(String name,String department){
        boolean temp = false;
        if(name == null){
            return temp;
        }

        student_database[3].setName("wwww");
        student_database[4].setDepartment("tsts");
        student_database[point].setName(name);
        student_database[point].setDepartment(department);
        System.out.println(student_database[point].getName());
        temp = true;
        point++;
        return temp;
    }

    /*Student pop_student(int num){
        Student temp = null;
        if(num>=point){
            System.out.println("error!!");
            return temp;
        }

        temp.setDepartment(student_database[point].getDepartment());
        temp.setName(student_database[point].getName());
        point--;
        return temp;
    }*/

    boolean pop_student(int num){
        boolean temp = false;
        if(num>=point){
            return temp;
        }

        student_database[point] = null;
        point--;
        return temp;
    }

    Student[] list_all_student(){
        Student[] temp = new Student[point];
            for(int i=0;i<point;i++){
                temp[point].setDepartment(student_database[point].getDepartment());
                temp[point].setName(student_database[point].getName());
            }
            return temp;
        }

    Student search_one(int num){
        Student temp = null;
        if(num >= point){
            System.out.println("error!!");
            return temp;
        }

        temp.setDepartment(student_database[num].getDepartment());
        temp.setName(student_database[num].getName());
        return temp;
    }

}
 class management {
private DataBase dbms = new DataBase();

     boolean regisStudent(String name,String department){
        boolean temp = false;
        if(name == " "||department=="")
            return temp;

        temp=dbms.push_new_student(name,department);
        return temp;
    }

    public boolean unregisStudent(int id){
        boolean temp = false;
        if(id>0)
            temp = dbms.pop_student(id);
        return temp;
    }

    public String getStudentInfo(int id){
        String temp = "\t\t学生信息\n-----------------------------------------\n";
        temp += "编号\t 姓名\t 专业\n";
        Student student = dbms.search_one(id);
        if (student != null){
            temp += String.format("%s\t %s\t %s\n",
                    student.getId(),student.getName(),
                    student.getDepartment());
        }
        return temp;
    }

    public String getAllStudentsInfo(){
        String temp ="\t\t学生信息\n-------------------------------------------\n";
        temp += "编号\t姓名\t专业\n";
        Student[] all = dbms.list_all_student();
        if(all !=null){
            for (Student student : all){
                if(student == null)
                    continue;
                temp += String.format("%s\t %s\t %s\n",
                        student.getId(),student.getName(),
                        student.getDepartment());
            }
        }
        return temp;
    }

}

1个回答

beacon_2011
beacon_2011   Rxr 2016.05.05 17:46

贴一下报错信息吧,怎么个运行一半运行不了了,报错么

Csdn user default icon
上传中...
上传图片
插入图片