求大神,写个java完整代码,满足要求,在线等
1个回答
展开全部
public class Student {
private String stuNo;// 学号
private String stuName;// 学生名字
public Student(){}
public Student(String stuNo,String stuName){
this.stuNo = stuNo;
this.stuName = stuName;
}
public String getStuNo() {
return stuNo;
}
public void setStuNo(String stuNo) {
this.stuNo = stuNo;
}
public String getStuName() {
return stuName;
}
public void setStuName(String stuName) {
this.stuName = stuName;
}
}
public class Test {
static Map<String, Student> stuMap = new HashMap<String, Student>();
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
int choose = 0;
while(choose!=5){
System.out.println("**********菜 单**********");
System.out.println(" 1.添加学生");
System.out.println(" 2.查找学生");
System.out.println(" 3.修改学生");
System.out.println(" 4.删除学生");
System.out.println(" 5.退出系统");
Scanner input = new Scanner(System.in);
System.out.print("输入序号进行相应操作:");
choose = input.nextInt();
switch(choose){
case 1:
addStu();
break;
case 2:
searchStu();
break;
case 3:
updateStu();
break;
case 4:
deleteStu();
break;
}
}
}
public static void addStu(){
System.out.print("请输入学生姓名:");
String stuName = input.next();
System.out.print("请输入学生学号:");
String stuNo = input.next();
Student stu = new Student(stuNo,stuName);
stuMap.put(stu.getStuNo(), stu);
System.out.println("学号为:"+stu.getStuNo()+"的学生已添加");
}
public static void deleteStu(){
System.out.print("请输入你要删除学生的学号:");
String stuNo = input.next();
stuMap.remove(stuNo);
System.out.println("学号为:"+stuNo+"的学生已删除");
}
public static void updateStu(){
System.out.print("请输入你要修改学生的学号:");
String oldStuNo = input.next();
Student stu = stuMap.get(oldStuNo);
System.out.print("请输入修改后的学生学号:");
String stuNo = input.next();
System.out.print("请输入修改后的学生名字:");
String stuName = input.next();
stu.setStuNo(stuNo);
stu.setStuName(stuName);
if(!oldStuNo.equals(stuNo)){
stuMap.remove(oldStuNo);
stuMap.put(stu.getStuNo(), stu);
}
System.out.println("学号为:"+oldStuNo+"的学生信息已修改");
}
public static void searchStu(){
for(String key : stuMap.keySet()){
System.out.println("学号:"+stuMap.get(key).getStuNo()+"\t姓名:"+stuMap.get(key).getStuName());
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询