• 学生成绩管理系统


    实验内容:

    1、定义student 类,其中包括五个私有变量(stunumber,name,age,sex,score)。
    各成员的含义如下:
    变量 stunumber 为字符串类型 String,用于存储学生的学号(有 8 位数字组成)。
    变量 name 为字符串类型 String,用于存储学生的姓名。
    变量 age 为 int 类型,用于存储学生的年龄。
    变量 sex 为 boolean 类型,用于存储学生的性别,男生为 false,女生为true。变量 score 为 double 类型,用于存储学生的成绩。
    并对每个变量定义 get()(读取变量信息)和 set()(设置变量信息)的方法。
    赋初值方法包括五个参数,用于为变量(stunumber ,name,age,sex 和score)赋值。
    2、定义 StudentManager 类实现下列要求。
    (1)利用数组实现至少存储五个学生的信息;(将考生信息作为第一条记录)。
    (2)定义showStudent()方法打印输出所有的学生信息;
    (3)定义addStudent (stunumber, name,age,sex,score)方法增加一名新学生的信息,需要判断学号是否重复,如果重复提示用户,并禁止增加新学生信息;
    (4)定义deleteStudent(stunumber)方法删除一名学生信息(将该学生所有信息清空);
    (5)定义updateStudent (stunumber,name ,age ,sex ,score)方法修改学生信息;
    (6)定义selectStudent ( stunumber )查询并且输出该名学生的全部信息。
    (7)定义一个输入界面如下图所示,选择相应的数字执行相应的功能
    ***************************************************************
                    石家庄铁道大学信息科学与技术学院
                              学生信息管理系统 v2.0
    ****************************************************************
                              1、 遍历输出学生信息;
                              2、 新学生信息录入;
                              3、 删除学生信息;
                              4、 修改学生信息;
                              5、 查询学生信息;
    ****************************************************************

    程序测试截图如下:

    输入功能:

     

     主面板:

     遍历输出学生信息:

     

     新学生信息录入:

     

     

     删除学生信息:

     

     

     修改学生信息:

     

     

     

     查询学生信息:

     

     

    退出程序:

     代码如下:

    Student.java

     1 public class Student {
     2     protected String stunumber;//用于存储学生的学号(有 8 位数字组成)
     3     protected String name;//用于存储学生的姓名
     4     protected int age;//用于存储学生的年龄
     5     protected boolean sex;//用于存储学生的性别,男生为 false,女生为true
     6     protected double score;//用于存储学生的成绩
     7     public String getStunumber() {
     8         return stunumber;
     9     }
    10     public void setStunumber(String stunumber) {
    11         this.stunumber = stunumber;
    12     }
    13     public String getName() {
    14         return name;
    15     }
    16     public void setName(String name) {
    17         this.name=name;
    18     }
    19     public int getAge() {
    20         return age;
    21     }
    22     public void setAge(int age) {
    23         this.age=age;
    24     }
    25     public boolean getSex() {
    26         return sex;
    27     }
    28     public void setSex(boolean sex) {
    29         this.sex=sex;
    30     }
    31     public double getScore() {
    32         return score;
    33     }
    34     public void setScore(double score) {
    35         this.score=score;
    36     }
    37     //赋初值方法
    38     public void Value(String stunumber,String name,int age,boolean sex,double score) {
    39         this.setStunumber(stunumber);
    40         this.score=score;
    41         this.sex=sex;
    42         this.age=age;
    43         this.name=name;
    44     }
    45 }

    StudentManager.java

      1 import java.io.IOException;
      2 import java.util.Scanner;
      3 import java.lang.Object;
      4 public class StudentManager{
      5     public static int N=50;
      6     static Student[] student=new Student[N];
      7     static String[] stu=new String[N];
      8     public void Input() {
      9         Scanner in=new Scanner(System.in);
     10         System.out.println("请问你需要输入几位学生的信息:");
     11         int n=in.nextInt();
     12         Scanner s=new Scanner(System.in);
     13         System.out.println("请输入"+n+"位学生的信息:");
     14         for(int i=0;i<n;i++) {
     15             student[i]=new Student();
     16             System.out.println("第"+(i+1)+"位同学的信息:");
     17             System.out.print("学号:");
     18             student[i].stunumber=s.nextLine();
     19             System.out.print("姓名:");
     20             student[i].name=s.nextLine();
     21             System.out.print("年龄:");
     22             student[i].age=in.nextInt();
     23             System.out.print("性别(男生为 false,女生为true):");
     24             student[i].sex=in.nextBoolean();
     25             System.out.print("成绩:");
     26             student[i].score=in.nextDouble();
     27             stu[i]=student[i].stunumber+"  "+student[i].name+"  "+student[i].age+"  "+student[i].sex+"  "+student[i].score;
     28         }
     29     }
     30     public void showStudent() {//打印输出所有的学生信息
     31         for(int i=0;i<student.length;i++) {
     32             if(stu[i]==null) {
     33                 break;
     34             }
     35             System.out.println(stu[i]);
     36         }
     37     }
     38     public boolean judgement(String stunumber) {
     39         for(int i=0;i<student.length;i++) {
     40             if(student[i]==null)
     41                 break;
     42             if(student[i].getStunumber().contains(stunumber)) {
     43                 return true;
     44             }
     45         }
     46         return false;
     47     }
     48     public void addStudent(String stunumber,String name,int age,boolean sex,double score) {
     49         //增加一名新学生的信息,需要判断学号是否重复,如果重复提示用户,并禁止增加新学生信息
     50         int count=0;
     51         for(int i=0;i<stu.length;i++) {
     52             if(stu[i]==null)
     53                 break;
     54             count++;
     55         }
     56         stu[count]=stunumber+"  "+name+"  "+age+"  "+sex+"  "+score;
     57     }
     58     public void deleteStudent(String stunumber) {
     59         //删除一名学生信息(将该学生所有信息清空)
     60         for(int i=0;i<student.length;i++) {
     61             if(student[i]==null)
     62                 break;
     63             if(student[i].getStunumber().contains(stunumber)) {
     64                 for (int j = i; j < student.length - 1; j++)
     65                 {
     66                     stu[j] = stu[j + 1];
     67                 }
     68             }
     69         }
     70         System.out.println("删除成功!");
     71     }
     72     public void updateStudent(String stunumber,String name,int age,boolean sex,double score) {
     73         //修改学生信息
     74         for(int i=0;i<student.length;i++) {
     75             if(student[i]==null)
     76                 break;
     77             if(student[i].getStunumber().contains(stunumber)) {
     78                 student[i].stunumber=stunumber;
     79                 student[i].name=name;
     80                 student[i].age=age;
     81                 student[i].sex=sex;
     82                 student[i].score=score;
     83                 stu[i]=student[i].stunumber+"  "+student[i].name+"  "+student[i].age+"  "+student[i].sex+"  "+student[i].score;
     84                 System.out.println("修改成功!");
     85             }
     86         }
     87     }
     88     public void selectStudent(String stunumber) {
     89         //查询并且输出该名学生的全部信息
     90         for(int i=0;i<student.length;i++) {
     91             if(student[i]==null)
     92                 break;
     93             if(student[i].getStunumber().contains(stunumber)) {
     94                 System.out.println(stu[i]);
     95             }
     96             if(stu[i]==null)
     97                 break;
     98         }
     99     }
    100     public void print() {
    101         System.out.println("***************************************************************");
    102         System.out.println("                                                                 石家庄铁道大学信息科学与技术学院");
    103         System.out.println("                                                                         学生信息管理系统 v2.0");
    104         System.out.println("****************************************************************");
    105         System.out.println("                         1、 遍历输出学生信息;"); 
    106         System.out.println("                         2、 新学生信息录入;");
    107         System.out.println("                         3、 删除学生信息;");
    108         System.out.println("                         4、 修改学生信息;");
    109         System.out.println("                         5、 查询学生信息;");
    110         System.out.println("****************************************************************");
    111         System.out.print("请选择:");
    112     }
    113     public static void main(String[] args) throws IOException{
    114         int t=0;
    115         StudentManager st=new StudentManager();
    116         st.Input();
    117         do {
    118             StudentManager studentmanger=new StudentManager();
    119             Scanner in=new Scanner(System.in);
    120             studentmanger.print();
    121             int q=in.nextInt();
    122             if(q==1) {//遍历输出学生信息
    123                 studentmanger.showStudent();
    124             }else if(q==2) {// 新学生信息录入
    125                 System.out.println("请输入新学生的信息:");
    126                 Scanner s=new Scanner(System.in);
    127                 Scanner o=new Scanner(System.in);
    128                 System.out.print("学号:");
    129                 String stunumber=s.nextLine();
    130                 System.out.print("姓名:");
    131                 String name=o.nextLine();
    132                 System.out.print("年龄:");
    133                 int age=o.nextInt();
    134                 System.out.print("性别(男生为 false,女生为true):");
    135                 boolean sex=o.nextBoolean();
    136                 System.out.print("成绩:");
    137                 double score=o.nextDouble();
    138                 boolean ju=studentmanger.judgement(stunumber);
    139                 if(ju=true) {
    140                     studentmanger.addStudent(stunumber,name,age,sex,score);
    141                 }else {
    142                     System.out.println("输入的此学生学号已经存在,请重新输入!");
    143                 }
    144             }else if(q==3) {//删除学生信息
    145                 System.out.println("请输入需要删除的学生的信息的学号:");
    146                 Scanner f=new Scanner(System.in);
    147                 String stunumber=f.nextLine();
    148                 studentmanger.deleteStudent(stunumber);
    149             }else if(q==4) {//修改学生信息
    150                 System.out.println("请输入需要修改的学生的学号:");
    151                 Scanner s=new Scanner(System.in);
    152                 Scanner o=new Scanner(System.in);
    153                 System.out.print("学号:");
    154                 String stunumber=s.nextLine();
    155                 System.out.println("请输入该学号学生修改后的信息:");
    156                 System.out.print("姓名:");
    157                 String name=o.nextLine();
    158                 System.out.print("年龄:");
    159                 int age=o.nextInt();
    160                 System.out.print("性别(男生为 false,女生为true):");
    161                 boolean sex=o.nextBoolean();
    162                 System.out.print("成绩:");
    163                 double score=o.nextDouble();
    164                 studentmanger.updateStudent(stunumber,name,age,sex,score);
    165             }else if(q==5) {//查询学生信息
    166                 System.out.println("请输入需要查询的学生的信息的学号:");
    167                 Scanner f=new Scanner(System.in);
    168                 String stunumber=f.nextLine();
    169                 studentmanger.selectStudent(stunumber);
    170             }else {
    171                 System.out.println("输入错误,已退出此程序!");
    172                 System.exit(0);
    173             }
    174             System.out.println("请问是返回主菜单还是退出,请输入:");
    175             System.out.println("1.返回主菜单");
    176             System.out.println("2.退出");
    177             t=in.nextInt();
    178             if(t==2) {
    179                 System.out.println("已退出此程序!");
    180                 System.exit(0);
    181             }
    182             if(t!=2&&t!=1) {
    183                 System.out.println("输入错误,已退出此程序!");
    184                 System.exit(0);
    185             }
    186         }while(t==1);        
    187     }
    188 }
  • 相关阅读:
    英国下院通过法案允许合成人兽胚胎
    老外关于思考时间的问与答
    性能测试中用LambdaProbe监控Tomcat
    BT下载原理
    汽车维修行业呼吁大学生加入修车行列
    一个女研究生(高级测试工程师)的职业选择
    微软称20日验证Windows与Office 盗版将黑屏 网友评论
    Xbox摇身变NAS:BT的使用问题与性能测试
    李开复建言大学生:求职中不要把钱看得太重
    IBM雇员将罢工15分钟 为抗议公司裁员
  • 原文地址:https://www.cnblogs.com/miao-com/p/13513823.html
Copyright © 2020-2023  润新知