简单的学生管理系统,在CaiDan类中的switch语句中参数不知该如何写了,求指教,有附文件
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;
}
}
student1.2.zip
(7.71 KB)