zoukankan      html  css  js  c++  java
  • 函数调用实例:学生管理系统(前面的优化版),可以弹出窗口。

      1 package classwork308;
      2 /*
      3  * 学生管理系统
      4  */
      5 import javax.swing.JOptionPane;
      6 
      7 public class Method_StudentManage {
      8       
      9     /*****管理账号*****/
     10     public static String[] manager={"a","b"};
     11     /*****管理密码*****/
     12     public static int [] password={1,2};
     13     /*****学生姓名数组*****/
     14     public static String[] name=new String[30];
     15     /*****学生学号数组*****/
     16     public static int[] code=new int[30];
     17     /*****学生分数数组*****/
     18     public static int[] grade=new int[30];
     19     /*****记录学生的多少*****/
     20     public static int number=0;
     21     
     22     public static void main(String[] args) {
     23         register();    
     24     }
     25     
     26     //管理员登录
     27     public static void register(){
     28         JOptionPane.showMessageDialog(null, "欢迎光临!");
     29         int a=-1,b=0;
     30         while(true){    
     31         String str=JOptionPane.showInputDialog(null, "请输入用户名");
     32         String str1=JOptionPane.showInputDialog(null, "请输入密码");
     33         int temp=Integer.parseInt(str1);
     34             for(int i=0;i<manager.length;i++){
     35             if(str.equals(manager[i])&&temp==password[i]){//登录成功
     36                 os();
     37                 a=1;
     38             }            
     39             }
     40            if(a==-1){
     41                 if(b==3){
     42                    JOptionPane.showMessageDialog(null, "非法用户");
     43                    System.exit(0);
     44                 }
     45                 JOptionPane.showMessageDialog(null, "用户名或密码错误");
     46                 b++;
     47             }         
     48         }
     49     }
     50     //选择界面
     51     public static void os(){
     52         while(true){
     53         String s=JOptionPane.showInputDialog(null,"1、添加
    2、显示
    3、删除
    4、查询
    5、修改
    6、排序
    7、退出
    ");
     54         int temp=Integer.parseInt(s);
     55         switch (temp) {
     56         case 1:
     57             add();
     58             break;
     59         case 2:
     60             show();
     61             break;
     62         case 3:
     63             delete();
     64             break;
     65         case 4:
     66             demand();
     67             break;
     68         case 5:
     69             modification();
     70             break;
     71         case 6:
     72             sort();
     73             break;
     74         case 7:
     75             System.exit(0);
     76             break;
     77 
     78         default:
     79             JOptionPane.showMessageDialog(null, "请输入1——7之间的数");
     80             break;
     81         }
     82         }
     83     }
     84     //添加
     85     public static void add(){
     86         String str1=JOptionPane.showInputDialog(null,"请输入学号");
     87         String str2=JOptionPane.showInputDialog(null, "请输入姓名");
     88         String str3=JOptionPane.showInputDialog(null, "请输入分数");
     89         int temp1=Integer.parseInt(str1);
     90         int temp3=Integer.parseInt(str3);
     91         code[number]=temp1;
     92         name[number]=str2;
     93         grade[number]=temp3;
     94         number++;    
     95     }
     96     //删除
     97     public static void delete(){
     98         String str=JOptionPane.showInputDialog(null,"请输入姓名");
     99         int a=-1;
    100         for(int i=0;i<number;i++){
    101             if(str.equals(name[i])){
    102                 for(int j=i;j<number-1;j++){
    103                     name[j]=name[j+1];
    104                     code[j]=code[j+1];
    105                     grade[j]=grade[j+1];
    106                     
    107                 }
    108                 a=1;
    109                 number--;
    110                 show();
    111                 break;            
    112             }        
    113         }
    114         if(a==-1){
    115             JOptionPane.showMessageDialog(null, "没有找到该学生");
    116         }
    117     }
    118     //修改
    119     public static void modification(){
    120         String str=JOptionPane.showInputDialog(null,"请输入姓名");
    121         int a=-1;
    122         for (int i = 0; i < number; i++) {
    123             if(str.equals(name[i])){
    124                 a=i;
    125                 String str1=JOptionPane.showInputDialog(null,"请输入学号");
    126                 String str2=JOptionPane.showInputDialog(null,"请输入成绩");
    127                 int temp1=Integer.parseInt(str1);
    128                 int temp2=Integer.parseInt(str2);
    129                 name[i]=JOptionPane.showInputDialog(null, "请输入姓名");
    130                 code[i]=temp1;
    131                 grade[i]=temp2;
    132                 show();
    133             }
    134         }
    135         if(a==-1){
    136             JOptionPane.showMessageDialog(null, "没有找到该学生");
    137         }
    138         
    139     }
    140     //查询
    141     public static void demand(){
    142         String str=JOptionPane.showInputDialog(null,"请输入姓名");
    143         int a=-1;
    144         for (int i = 0; i < number; i++) {
    145             if(str.equals(name[i])){
    146                 a=i;
    147                 String s="学号          姓名           成绩
    ";
    148                 s=s+code[i]+"            "+name[i]+"            "+grade[i];    
    149                 JOptionPane.showMessageDialog(null, s);    
    150             }
    151         }
    152         if(a==-1){
    153             JOptionPane.showMessageDialog(null, "没有找到该学生");
    154         }    
    155     }
    156     //按成绩降序排序
    157     public static void sort(){
    158         int temp,temp1;
    159         String temp3;
    160         for (int i = 0; i < number-1; i++) {
    161             for(int j=i+1;j<number;j++){
    162                 if(grade[i]<grade[j]){
    163                     temp=grade[i];
    164                     grade[i]=grade[j];
    165                     grade[j]=temp;
    166                     temp1=code[i];
    167                     code[i]=code[j];
    168                     code[j]=temp1;
    169                     temp3=name[i];
    170                     name[i]=name[j];
    171                     name[j]=temp3;                    
    172                 }
    173             }
    174         }
    175         show();
    176     }
    177     //显示所有学生信息
    178     public static void show(){
    179         String s="学号          姓名           成绩
    ";
    180         for (int i = 0; i < number; i++) {
    181             s=s+code[i]+"                "+name[i]+"                     "+grade[i]+"
    ";    
    182         }
    183         JOptionPane.showMessageDialog(null, s);    
    184     }   
    185 }
  • 相关阅读:
    「CSP-S 2019」树的重心「重心」
    「SDOI2017」天才黑客「优化建图最短路」
    「NOI Online Round2」 题解
    Qt 自定义序列化
    Android 定制化apk生成
    gradle上传jar包到maven公共仓库
    JAVA 插入注解处理器
    使用docker安装gitlab
    数据库递归树形查询优化
    JDBCTemplate使用
  • 原文地址:https://www.cnblogs.com/jichuang/p/6523053.html
Copyright © 2011-2022 走看看