学生信息管理系统
昨天简单写了个学生管理系统,诸位可以对我的代码指点一下,但不要指指点点
student类
package com.briup.day19;
/*
* 写一个完整版学生管理系统
具有登陆功能,用户名为 admin 以及密码
查询学生信息
修改学生信息
删除学生信息
*/
public class Student {
private int id;
private String name;
private int age;
public Student() {
}
public Student(String name, int age) {
this.name = name;
this.age = age;
}
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;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Student [id=" + id + ", name=" + name + ", age=" + age + "]";
}
}
ShowAllPage类
package com.briup.day19;
public class ShowAllPage {
public static void showPage() {
System.out.println("*********************");
System.out.println("*****学生管理系统*****");
System.out.println(" 按照以下格式 ");
System.out.println(" 输入用户名和密码 ");
System.out.println(" 用户名:密码 ");
System.out.println("*********************");
}
public static void showPage1() {
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("******6.删除全部学生信息 *****");
System.out.println("******7.退出学生信息管理系统**");
System.out.println("*****************************");
}
}
MapTest类
package com.briup.day19;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Set;
import com.briup.day12.Test1.Add;
public class MapTest {
static Map<Integer, Student> map = new HashMap<>();
public static void main(String[] args) {
for (int i = 3; i > 0; i--) {
ShowAllPage.showPage();
Scanner sc = new Scanner(System.in);
String userInfo = sc.nextLine();
String[] userInfo1 = userInfo.split(":");
if ("admin".equals(userInfo1[0]) && "admin".equals(userInfo1[1])) {
System.out.println("登陆成功!!");
boolean flag = true;
while (flag) {
ShowAllPage.showPage1();
Scanner sP1 = new Scanner(System.in);
int key = sP1.nextInt();
switch (key) {
case 1: // 1.添加学生信息
System.out.println("请输入学生学号:姓名:年纪");
Scanner st = new Scanner(System.in);
String student = st.nextLine();
String[] student1 = student.split(":");
Student stu = new Student();
stu.setId(Integer.parseInt(student1[0]));
stu.setName(student1[1]);
stu.setAge(Integer.parseInt(student1[2]));
map.put(stu.getId(), stu);
// Set<Entry<Integer,Student>> set =
// map.entrySet();//遍历输出学生
// for (Entry<Integer, Student> entry : set) {
System.out.println(map);
// }
break;
case 2: // 2.查询所有学生信息
System.out.println(map);
break;
case 3: // 3.查询学生信息
System.out.println("请输入学号查询学生信息");
Scanner st1 = new Scanner(System.in);
int id1 = st1.nextInt();
Set<Entry<Integer, Student>> entrySet = map.entrySet();
for (Entry<Integer, Student> entry : entrySet) {
if (entry.getKey() == id1) {
System.out.println(entry.getKey() + ":" + entry.getValue());
} else {
System.out.println("暂无学号为" + id1 + "的学生信息");
}
break;
}
break;
case 4: // 4.修改学生信息
System.out.println("请输入要修改的学生号");
Scanner st2 = new Scanner(System.in);
int id2 = st2.nextInt();
Set<Entry<Integer, Student>> entrySet2 = map.entrySet();
for (Entry<Integer, Student> entry : entrySet2) {
if (entry.getKey() == id2) {
System.out.println("请输入要修改的学生学号:姓名:年纪");
Scanner st3 = new Scanner(System.in);
String student2 = st3.nextLine();
String[] student11 = student2.split(":");
Student stu1 = new Student();
stu1.setId(Integer.parseInt(student11[0]));
stu1.setName(student11[1]);
stu1.setAge(Integer.parseInt(student11[2]));
map.replace(stu1.getId(), stu1);
}
}
break;
case 5: // 5.删除学生信息
System.out.println("请输入要删除的学生学号");
Scanner st4 = new Scanner(System.in);
Integer student3 = st4.nextInt();
map.remove(student3);
System.out.println("删除成功!!");
break;
case 6: // 6.删除全部学生信息
map.clear();
System.out.println("清除全部学生信息成功!!");
break;
case 7: // 7.退出学生信息管理系统
flag = false;
break;
}
}
} else {
System.out.println("账户或密码输入错误!!你还有" + i + "次机会!!");
}
}
}
}