import javax.swing.JOptionPane;
public class Studentone {public int code;
public String name;
public int grade;
}
/** 主界面 */
public class Studentfor {
public static Studentone[] stu = new Studentone[20];
public static int number = 0;
public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "欢迎光临学生管理系统");
boolean island = login();
while (true) {
if (island == true) {
String s = JOptionPane.showInputDialog(null,
"1、添加\n2、显示\n3、查找\n4、删除\n5、修改\n6、排序\n7、退出\n");
int x = Integer.parseInt(s);
switch (x) {
case 1:
tianjia();
break;
case 2:
xianshi();
break;
case 3:
shanchu();
break;
case 4:
chazhao();
break;
case 5:
xiugai();
break;
case 6:
paixu();
break;
case 7:
JOptionPane.showMessageDialog(null, "请退出系统");
System.exit(0);
break;
default:
JOptionPane.showMessageDialog(null, "请输入1-7");
break;
}
}
}
}
/** 排序 */
public static void paixu() {
for (int i = 0; i < number; i++) {
for (int j = i + 1; j < number; j++) {
if (stu[i].grade < stu[j].grade) {
Studentone s = stu[i];
stu[i] = stu[j];
stu[j] = s;
}
}
}
xianshi();
}
/** 修改 */
public static void xiugai() {
int index = findbyname();
if (index != -1) {
String code = JOptionPane.showInputDialog(null, "请输入学号");
String name = JOptionPane.showInputDialog(null, "请输入姓名");
String grade = JOptionPane.showInputDialog(null, "请输入成绩");
Studentone s = new Studentone();
s.code = Integer.parseInt(code);
s.name = name;
s.grade = Integer.parseInt(grade);
}
}
/** 删除 */
public static void shanchu() {
int index = findbyname();
if (index != -1) {
}
for (int i = index; i < number - 1; i++) {
stu[i].code = stu[i + 1].code;
stu[i].name = stu[i + 1].name;
stu[i].grade = stu[i + 1].grade;
}
xianshi();
}
/** 查找 */
public static void chazhao() {
int index = findbyname();
if (index != -1) {
JOptionPane.showMessageDialog(null, "学号 姓名 成绩\n" + stu[index].code
+ " " + stu[index].name + " " + stu[index].grade);
}
xianshi();
}
/** 找出学生下标 */
public static int findbyname() {
String name = JOptionPane.showInputDialog(null, "请输入学生姓名");
for (int i = 0; i < number; i++) {
if (name.equals(stu[i].name)) {
return i;
}
}
JOptionPane.showMessageDialog(null, "无此人");
return -1;
}
/** 显示 */
public static void xianshi(){
String str = "学号 姓名 成绩\n";
for (int i = 0; i < number; i++) {
str += stu[i].code + " " + stu[i].name + " " + stu[i].grade + "\n";
}
JOptionPane.showMessageDialog(null, str);
}
/** 添加 */
public static void tianjia() {
String code = JOptionPane.showInputDialog(null, "请输入学号");
String name = JOptionPane.showInputDialog(null, "请输入姓名");
String grade = JOptionPane.showInputDialog(null, "请输入成绩");
Studentone s = new Studentone();
s.code = Integer.parseInt(code);
s.name = name;
s.grade = Integer.parseInt(grade);
number++;
}
/** 登录 */
public static boolean login() {
String x = JOptionPane.showInputDialog(null, "请输入用户名");
String y = JOptionPane.showInputDialog(null, "请输入密码");
if (x.equals("123") && y.equals("456")) {
JOptionPane.showMessageDialog(null, "登录成功");
return true;
} else {
JOptionPane.showMessageDialog(null, "用户名和密码错误");
return false;
}
}
}