注册 登录
编程论坛 JAVA论坛

简单的学生管理系统,在CaiDan类中的switch语句中参数不知该如何写了,求指教,有附文件

牧城雪 发布于 2018-06-23 17:18, 3115 次点击
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class Student {
    private String name;
    private String id;
    private int age;
    private Date birth;
    public Student(String name, String id, int age, Date birth) {
        super();
        this.name = name;
        this.id = id;
        this.age = age;
        this.birth = birth;
    }
    public Student() {
        super();
    }
    public static Student inputStudent() {
        Student s=new Student();
        Scanner in=new Scanner(System.in);
        System.out.println("输入学生姓名");
        s.name=in.next();
        System.out.println("输入学生学号");
        s.id=in.next();
        System.out.println("输入学生年龄");
        s.age=in.nextInt();
        System.out.println("输入学生生日");
String sd=in.next();
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        try {
            s.birth=sdf.parse(sd);
        } catch (ParseException e) {
            s.birth=new Date();
        }
        return s;
    }
    public void shownStudent() {
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        System.out.println(this.name+"\t"+this.id+"\t"+this.age+"\t"+sdf.format(this.birth));
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public Date getBirth() {
        return birth;
    }
    public void setBirth(Date birth) {
        this.birth = birth;
    }
    @Override
    public boolean equals(Object arg0) {
        if(arg0 instanceof Student) {
            Student s=(Student) arg0;
            if(s!=null && this!=null && s.id==this.id) {
                return true;
            }
        }
        return false;
    }
}

package ctrl;
import java.util.ArrayList;
import model.Student;
public class GuanLi {
    ArrayList <Student> students=new ArrayList <Student> ();
    public void addStudent() {
        Student s=Student.inputStudent();
        if(students.contains(s)) {
            System.out.println("此学生已存在,无需操作");
        }else {
            students.add(s);
        }
    }
    public void seekById(String id) {
        Student s=new Student();
        s.setId(id);
        int index=students.indexOf(s);
        if(index!=-1) {
            students.get(index).shownStudent();
        }else {
            System.out.println("查找的学生不存在");
        }
    }
    public void deleteById(String id) {
        Student s=new Student();
        s.setId(id);
        if(students.remove(s)) {
    System.out.println("删除成功");
        }else {
            System.out.println("删除失败");
        }
    }
}

package view;
import java.util.Scanner;
import ctrl.GuanLi;
import model.Student;
public class CaiDan {
    public static void main(String[] args) {
        GuanLi c=new GuanLi();
        CaiDan s=new CaiDan();
        while(true) {
            int i=s.xuanXiang();
            switch(i) {
            case 1:
                c.addStudent();
                break;
            case 2:
                c.seekById();
                break;
            case 3:
                c.deleteById();
                break;
            }
            
        }

    }
    public int xuanXiang() {
        System.out.println("1.添加学生信息");
        System.out.println("2.查找学生信息");
        System.out.println("3.删除学生信息");
        System.out.println("4.修改学生信息");
        System.out.println("5.退出");
        Scanner in=new Scanner(System.in);
        int i=in.nextInt();
        return i;
    }

}
只有本站会员才能查看附件,请 登录


























8 回复
#2
林月儿2018-06-23 17:43
CaiDan类中的switch语句中参数不知该如何写了?

这个写的学生管理系统?
#3
牧城雪2018-06-23 17:51
回复 2楼 林月儿
嗯嗯,简单的学生管理
#4
林月儿2018-06-23 18:11
你想问什么?
#5
牧城雪2018-06-23 18:18
回复 4楼 林月儿
while(true) {
            int i=s.xuanXiang();
            switch(i) {
            case 1:
                c.addStudent();
                break;
            case 2:
                c.seekById();
                break;
            case 3:
                c.deleteById();
                break;
case 2,case 3中添加参数该怎样添加
#6
牧城雪2018-06-23 18:18
回复 4楼 林月儿
while(true) {
            int i=s.xuanXiang();
            switch(i) {
            case 1:
                c.addStudent();
                break;
            case 2:
                c.seekById();
                break;
            case 3:
                c.deleteById();
                break;
case 2,case 3中添加参数该怎样添加
#7
林月儿2018-06-23 18:21
在下一个流程添加参数不就好了,进了addStudent方法执行接受参数的流程啊
#8
牧城雪2018-06-25 10:18
回复 7楼 林月儿
谢谢,已经找到问题所在。
#9
五线谱2019-06-27 21:26
回复 8楼 牧城雪
分享一下
1