Java design simple student management system

This example shares the java student achievement management system for your reference. The specific contents are as follows

requirement:

Perfect the student class, which includes student number, name, grade, major Grades in three subjects (English, advanced mathematics and computer), improve the score entry method, design the search method by student number, search method by name and sorting method by single subject score. Design the main class, instantiate the student array containing 5 student information, find and print the information of a student, and print the sorting letter of the 5 students according to the score of a subject from high to low Information (student number, name, grade); output the average score of three single subjects of all students.

First, create a student class and use the construction method to initialize the grades of student number, name, grade, major and three courses

First package in classification

Student class

Use the constructor to initialize the get and set methods to pass values

package swpu.student;

public class Student {
 public String number;
 public String name;
 public String major;

 public int math;
 public int computer;
 public int english;
 public int total;
 //对象数组初始化,使用构造方法
 public Student(String newname,String nmajor,String newnumber,int nmath,int ncom,int ne){
 number = newnumber;
 major =nmajor;
 name = newname;
 math = nmath;
 computer = ncom;
 english = ne;
 }
 public String getMajor() {
 return major;
 }
 public void setMajor(String major) {
 this.major = major;
 }
 public int getEnglish() {
 return english;
 }
 public void setEnglish(int english) {
 this.english = english;
 }
 public String getNumber() {
 return number;
 }
 public void setNumber(String number) {
 this.number = number;
 }
 public String getName() {
 return name;
 }
 public void setName(String name) {
 this.name = name;
 }
 public int getMath() {
 return math;
 }
 public void setMath(int math) {
 this.math = math;
 }
 public int getComputer() {
 return computer;
 }
 public void setComputer(int computer) {
 this.computer = computer;
 }

}

Sort class rank class

package swpu.student;

public class Rank {
 public static void rankscore(Student [] arr,int n){
 //数学
 if(n==1) {
 for (int i = 0; i < arr.length-1; i++) {
    int index = i;
    int j;
    // 找出最小值得元素下标
    for (j = i + 1; j < arr.length; j++) {
     if (arr[j].math > arr[index].math) {
      index = j;
     }
    }
    int tmp = arr[index].math;
    arr[index].math = arr[i].math;
    arr[i].math = tmp;
   }
 }
 //英语
  if(n==2) {
  for (int i = 0; i < arr.length-1; i++) {
    int index = i;
    int j;
    // 找出最小值得元素下标
    for (j = i + 1; j < arr.length; j++) {
     if (arr[j].english > arr[index].english) {
      index = j;
     }
    }
    int tmp = arr[index].english;
    arr[index].english = arr[i].english;
    arr[i].english = tmp;
   }
  }
  //计算机
  if(n==3) {
  for (int i = 0; i < arr.length-1; i++) {
    int index = i;
    int j;
    // 找出最小值得元素下标
    for (j = i + 1; j < arr.length; j++) {
     if (arr[j].computer > arr[index].computer) {
      index = j;
     }
    }
    int tmp = arr[index].computer;
    arr[index].computer = arr[i].computer;
    arr[i].computer = tmp;
   }
  }
  }
}

Here, the static method is used to pass in the value of the score

Find classsearch class

package swpu.student;

public class Search {
 //书写两种方法(学号,姓名)

 public int StuNum(Student arr[],String y)//传入数组,查找值,使用字符串的比较
 {
 for(int i = 0;i<arr.length;i++)
 {
 if(arr[i].number.equals(y))
 return i;
 }
 return -1;
 }
 public int StuNam(Student stu[],String x) {
 for(int i = 0;i<stu.length;i++)
 {
 if(stu[i].name.equals(x))
 return i;
 }
 return -1;
 }
}

Main category

Intudent class

package swpu.student;
import java.util.Scanner;
public class Instudent {

 public static void main(String[] args) {
 // TODO Auto-generated method stub
 Scanner in = new Scanner(system.in);
 Student []stu = new Student[5];
 //学生成绩初始化
 stu[0] = new Student("Jack","软工 ","20183101",80,90,85);
 stu[1] = new Student("Rose","大数据","20183102",99,93,90);
 stu[2] = new Student("John","网安全","20183103",87,70,74);
 stu[3] = new Student("Andi","网工程","20183104",67,66,68);
 stu[4] = new Student("Mike","物联网","20183105",56,55);
 //局部变量的初始化
 String nu1 = "";
 String na1 = "";
 String ma1 = "";
 int t1=0,t2=0,t3=0;
 System.out.println("-------------------学生成绩管理系统------------------------");
 //输入学生信息
 for(int i=0;i<stu.length;i++) {
  System.out.println("请输入第"+(i+1)+"个学生的姓名,专业,学号,数学成绩,计算机成绩,英语成绩");
  na1 = in.next();//姓名
  ma1 = in.next();//专业
  nu1 = in.next();//学号
  t1 = in.nextInt();
  t2 = in.nextInt();
  t3 = in.nextInt();
  stu[i].setNumber(nu1);
  stu[i].setName(na1);
  stu[i].setMajor(ma1);
  stu[i].setEnglish(t3);
  stu[i].setComputer(t2);
  stu[i].setMath(t2);
  }
 Search search = new Search();
 //选择需要的查找的方法
 System.out.println("选择需要的查找的方法,1学号,2姓名");
 int p = in.nextInt();
 if(p==1) {
 //使用学号的方法进行查找
 System.out.println("输入您所需要查找的学生学号");
 String y = in.next();
 int x = search.StuNum(stu,y);
 if(x>=0)
 System.out.println("学号:"+stu[x].number+" 学生:"+stu[x].name+" 专业:"+stu[x].major+" 数学:"+stu[x].math+" 计算机:"+stu[x].computer+" 英语:"+stu[x].english);
 else
 System.out.println("输入的学生不存在");
 }
 if(p==2) {
 //使用姓名的方法进行查找
 System.out.println("输入您所需要查找的学生姓名");
 String thename = in.next();
 int w = search.StuNam(stu,thename);
 if(w>=0)
 System.out.println("学号:"+stu[w].number+" 学生:"+stu[w].name+" 专业:"+stu[w].major+" 数学:"+stu[w].math+" 计算机:"+stu[w].computer+" 英语:"+stu[w].english);
 else
 System.out.println("输入的学生不存在");
 }
 System.out.println("是否需要对单科成绩进行排名 [Y/N] 1 =yes,2=no");
 int op = in.nextInt();
 if(op==1) {
 //单科成绩的排序(输入所需要科目然后直接进行排序)
 Rank rank = new Rank();//创建对象
 System.out.println("输入所需要排序的成绩编号,1:数学,2:英语,3:计算机");
 int major = in.nextInt();
 rank.rankscore(stu,major);
 //输出排序后的成绩
 for(int i = 0;i < stu.length;i++) {
 System.out.println("学号:"+stu[i].number+" 学生:"+stu[i].name+" 专业:"+stu[i].major+" 数学:"+stu[i].math+" 计算机:"+stu[i].computer+" 英语:"+stu[i].english);
 }
 }
 else {
 System.out.println("结束,退出系统");
 }
 }

}

The value has been stored when initializing with the construction method. Therefore, when using the set method to input student information, it is actually to modify student information. When initializing the construction method, it can not be so complex. It can be directly based on the data type, for example:

stu[0] = new Student(" "," ",0);
stu[1] = new Student(" ",0);
stu[2] = new Student(" ",0);
stu[3] = new Student(" ",0);
stu[4] = new Student(" ",0);

Note that you must remember initialization when declaring local variables, otherwise an error will be reported when passing values into the array

Operation screenshot:

The above is the whole content of this article. I hope it will help you in your study, and I hope you will support us a lot.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>