您的位置:首页 > 编程语言 > Java开发

Java心得8

2015-08-06 22:12 459 查看
今天做了一个项目,是关于学生信息管理系统的,下面跟大家分享一下:

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;

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: