Java心得8

             今天做了一个项目,是关于学生信息管理系统的,下面跟大家分享一下:

import javax.swing.JOptionPane;


public class Xuesheng {

public static int[] cade = new int[20];
public static String[] name = new String[20];
public static int[] grade = new int[20];
public static int number = 0;


public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "欢迎光临学生管理系统");
boolean island = login();
if (island == false) {
JOptionPane.showMessageDialog(null, "非法用户");
System.exit(0);
}
while (true) {
String s = JOptionPane.showInputDialog(null,
"1、添加\n2、显示\n3、删除\n4、查找\n5、修改\n6、排序\n7、退出");
int a = Integer.parseInt(s);
switch (a) {
case 1:
add();
break;
case 2:
show();
break;
case 3:
del();
break;
case 4:
find();
break;
case 5:
update();
break;
case 6:
sort();
break;
case 7:
System.exit(0);
default:
JOptionPane.showInputDialog(null, "请输入选项");
}


}


}


public static void add() {


String x = JOptionPane.showInputDialog(null, "请输入学号");
String y = JOptionPane.showInputDialog(null, "请输入姓名");
String z = JOptionPane.showInputDialog(null, "请输入成绩");
cade[number] = Integer.parseInt(x);
name[number] = y;
grade[number] = Integer.parseInt(z);
number++;
// show();
}


public static void show() {


String s = "学号        姓名        成绩\n";
for (int i = 0; i < number; i++) {
s += cade[i] + "    " + name[i] + "    " + grade[i] + "\n";
}
JOptionPane.showMessageDialog(null, s);
}


public static void del() {
int index = findbyname();
if (index != -1) {
for (int i = index; i < number - 1; i++) {
cade[i] = cade[i + 1];
name[i] = name[i + 1];
grade[i] = grade[i + 1];
}
number--;
show();
}
}


public static void find() {
int index = findbyname();
        if(index!=-1){
JOptionPane.showMessageDialog(null, "学号:" + cade[index] +"  "+ " 姓名:   "
+ name[index] +"  "+ " 成绩:   " + grade[index]);
            }
}


public static void update() {
int index = findbyname();


String p = JOptionPane.showInputDialog(null, "请重新输入学号");
String f = JOptionPane.showInputDialog(null, "请重新输入姓名");
String t = JOptionPane.showInputDialog(null, "请重新输入成绩");


cade[index] = Integer.parseInt(p);
name[index] = f;
grade[index] = Integer.parseInt(t);
show();
}


public static void sort() {
int temp;
for(int i=0;i<number;i++){
for(int j = i+1;j<number;j++){
if(grade[i]<grade[j]){
temp=grade[i];
grade[i]=grade[j];
grade[j]=temp;

temp=cade[i];
cade[i]=cade[j];
cade[j]=temp;

String tp=name[i];
name[i]=name[j];
name[j]=tp;
}
}
}
show();


}


public static int findbyname() {
String m = JOptionPane.showInputDialog(null, "请输入姓名");


int index = -1;


for (int i = 0; i < number; i++) {
if (m.equals(name[i])) {
index = i;


return i;
}
}
if (index == -1) {
JOptionPane.showMessageDialog(null, "查无此人");


}
return -1;


}


public static boolean login() {
for (int i = 0; i < 3; i++) {
String name = JOptionPane.showInputDialog(null, "请输入用户名");
String pwd = JOptionPane.showInputDialog(null, "请输入密码");
if (name.equals("陈建勇") && pwd.equals("123456")) {
return true;
} else {
JOptionPane.showMessageDialog(null, "用户名或密码错误");
}
}
return false;
}


}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值