分享

学生成绩管理系统(小程序代码)

 文化龙乡 2019-11-12
学生成绩管理系统(小程序代码)

package day1;

import javax.swing.JOptionPane;

public class day1HomeWork {

public static String[] number = new String[20];

public static String[] name = new String[20];

public static double[] score = new double[20];

public static int num = 0;

public static void main(String[] args) {

// TODO Auto-generated method stub

JOptionPane.showMessageDialog(null,'欢迎光临');

boolean flag = login();

if (flag == false){

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

System.exit(-1);

}

while (true){

String input = JOptionPane.showInputDialog(null,'1、添加\n2、显示\n'

+ '3、删除\n4、查找\n5、修改\n6、排序\n7、退出');

char ch = input.toCharArray()[0];

switch (ch){

case '1':

addStudent();

break;

case '2':

showStudent();

break;

case '3':

deleteStudent();

break;

case '4':

queryStudent();

break;

case '5':

updateStudent();

break;

case '6':

sortStudent();

break;

case '7':

JOptionPane.showMessageDialog(null,'谢谢使用');

System.exit(-1);

break;

default:

JOptionPane.showMessageDialog(null, '输入有误,请重新输入(1-7)');

}

}

}

public static boolean login(){//登录

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

String userName = JOptionPane.showInputDialog(null,'请输入用户名');

int pwd = Integer.parseInt(JOptionPane.showInputDialog(null,'请输入密码'));

if (userName.equals('lwz') && pwd == 1992){

return true;

}

else{

JOptionPane.showMessageDialog(null,'用户名或密码错误');

}

}

return false;

}

public static void addStudent(){//添加学生信息

String codeStr = JOptionPane.showInputDialog(null,'请输入学号');

String nameStr = JOptionPane.showInputDialog(null,'请输入姓名');

double grade = Double.parseDouble(JOptionPane.showInputDialog(null,'请输入成绩'));

number[num] = codeStr;

name[num] = nameStr;

score[num] = grade;

num++;

}

public static void showStudent(){//显示学生信息

String str = '学号 姓名 成绩\n';

for (int i=0; i

// if (number[i] == null)

// continue;

str += number[i]+' '+name[i]+' '

+score[i]+'\n';

}

JOptionPane.showMessageDialog(null,str);

}

public static void deleteStudent(){//删除学生信息

String input = JOptionPane.showInputDialog(null, '请输入姓名');

int index = -1;

for (int i=0; i

if (name[i].equals(input)){

index = i;

}

}

if (index == -1){

JOptionPane.showMessageDialog(null, '没有找到该学生');

return;

}

for (int i=index; i

number[i] = number[i+1];

name[i] = name[i+1];

score[i] = score[i+1];

}

num--;

showStudent();

}

public static void queryStudent(){//查找

int index = -1;

String str = '学号 姓名 成绩\n';

String input = JOptionPane.showInputDialog(null,'请输入姓名');

for (int i=0; i

if (name[i].equals(input)){

index = i;

str += number[i]+' '+name[i]+' '+score[i]+'\n';

}

}

if (index == -1){

JOptionPane.showMessageDialog(null,'没有找到该学生');

}

else{

JOptionPane.showMessageDialog(null,str);

}

}

public static void updateStudent(){//修改

int index = -1;

String input = JOptionPane.showInputDialog(null,'请输入姓名');

for (int i=0; i

if (name[i].equals(input)){

index = i;

String strNum = JOptionPane.showInputDialog(null,'请输入学号');

number[i] = strNum;

String strName = JOptionPane.showInputDialog(null,'请输入姓名');

name[i] = strName;

double s = Double.parseDouble(JOptionPane.showInputDialog(null,'请输入成绩'));

score[i] = s;

}

}

if (index == -1){

JOptionPane.showMessageDialog(null, '没有找到该学生');

return;

}

String str = '学号 姓名 成绩\n';

for (int i=0; i

str += number[i]+' '+name[i]+' '+score[i]+'\n';

}

JOptionPane.showMessageDialog(null, str);

}

public static void sortStudent(){//排序

for (int i=0; i

for (int j=i+1; j

if (score[i] < score[j]){

String s = number[i];

number[i] = number[j];

number[j] = s;

String n = name[i];

name[i] = name[j];

name[j] = n;

double temp = score[i];

score[i] = score[j];

score[j] = temp;

}

}

}

showStudent();

}

}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多