java添加系统类包_Java 类 对象 包

本文介绍了一个基于Java的XXX学生信息管理系统,包括登录验证、学生信息的添加、查找、显示、删除、修改以及排序功能。通过JOptionPane实现用户交互,适合学习Java GUI编程和数据结构应用。
摘要由CSDN通过智能技术生成

packageHw0420;importjavax.swing.JOptionPane;public classStuInfo {public static Student[] array = new Student[20];public static int stunum = 0;public static voidmain(String[] args) {

JOptionPane.showMessageDialog(null, "欢迎使用XXX学生管理系统");boolean bl =login();if (!bl) {

JOptionPane.showMessageDialog(null, "非法用户");

}while (true) {

String s= JOptionPane.showInputDialog(null, "1.添加\n2.显示\n3.删除\n4.查找\n5.修改\n6.排序\n7.退出");int input =Integer.parseInt(s);switch(input) {case 1:

add();break;case 2:

show();break;case 3:

del();break;case 4:

find();break;case 5:

mod();break;case 6:

sort();break;case 7:

JOptionPane.showMessageDialog(null, "感谢使用XXX学生管理系统");

System.exit(0);break;

}

}

}/*** 登录判断

*

* @return是否登录成功*/

public static booleanlogin() {for (int i = 0; i < 3; i++) {

String id= JOptionPane.showInputDialog(null, "请输入您的账号");

String pwd= JOptionPane.showInputDialog(null, "请输入您的密码");if(id.equals(pwd)) {return true;

}

}return false;

}/*** 添加*/

public static voidadd() {

String strcode= JOptionPane.showInputDialog(null, "请输入学生学号");

String strname= JOptionPane.showInputDialog(null, "请输入学生姓名");

String strgrade= JOptionPane.showInputDialog(null, "请输入学生成绩");

Student s= newStudent();在此完成对学生对象各个属性的初始化

s.number=Integer.parseInt(strcode);

s.name=strname;

s.grade=Integer.parseInt(strgrade);

array[stunum]=s;

stunum++;

}/*** 查找学生

*

* @return找到返回下标 找不到返回-1*/

public static intfindByname() {

String s= JOptionPane.showInputDialog(null, "请输入您要查找的学生姓名");for (int i = 0; i < stunum; i++) {if(s.equals(array[i].name)) {returni;

}

}

JOptionPane.showMessageDialog(null, "查无此人");return -1;

}/*** 显示*/

public static voidshow() {

String str= "学号 姓名 成绩\n";for (int i = 0; i < stunum; i++) {

str+= array[i].number + " " + array[i].name + " " +array[i].grade+ "\n";

}

JOptionPane.showMessageDialog(null, str);

}/*** 删除*/

public static voiddel() {int index =findByname();if (index != -1) {for (int i = index; i < stunum; i++) {

array[i]= array[i + 1];

}

JOptionPane.showMessageDialog(null, "已删除");

show();

stunum--;

}

}/*** 查找*/

public static voidfind() {int index =findByname();if (index != -1) {

String str= "学号:" + array[index].number + "\n" + "姓名:" + array[index].name + "\n" + "成绩:"

+array[index].grade;

JOptionPane.showMessageDialog(null, str);

}

}/*** 修改*/

public static voidmod() {int index =findByname();if (index != -1) {

String strcode= JOptionPane.showInputDialog(null, "请输入学生学号");

String strname= JOptionPane.showInputDialog(null, "请输入学生姓名");

String strgrade= JOptionPane.showInputDialog(null, "请输入学生成绩");

array[index].number=Integer.parseInt(strcode);

array[index].name=strname;

array[index].grade=Integer.parseInt(strgrade);

}

show();

}/*** 排序*/

public static voidsort() {for (int i = 0; i < stunum; i++) {for (int j = i + 1; j < stunum; j++) {if (array[i].grade >array[j].grade) {

Student s=array[i];

array[i]=array[j];

array[j]=s;

}

}

}

show();

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值