欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

java設(shè)計(jì)簡單學(xué)生管理系統(tǒng)

 更新時(shí)間:2019年09月25日 14:36:39   作者:入門小白sjx  
這篇文章主要為大家詳細(xì)介紹了java設(shè)計(jì)簡單學(xué)生管理系統(tǒng),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了java學(xué)生成績管理系統(tǒng),供大家參考,具體內(nèi)容如下

要求:

完善Student類,Student類包含學(xué)號、姓名、年級、專業(yè)、三門功課的成績(英語、高數(shù)、計(jì)算機(jī))的成員變量,完善成績錄入方法、設(shè)計(jì)按學(xué)號查找方法、按姓名查找方法、按單科成績排序的方法。
設(shè)計(jì)主類,實(shí)例化包含5個(gè)學(xué)生信息的學(xué)生數(shù)組,查找某一個(gè)學(xué)生的信息并打印出來,同時(shí)打印這5個(gè)學(xué)生按某一科成績的按高到低的排序信息(學(xué)號、姓名、成績);輸出所有學(xué)生的三門單科平均成績。

首先先創(chuàng)建一個(gè)student類
使用構(gòu)造方法來初始化
學(xué)號、姓名、年級、專業(yè)、三門功課的成績

先打包
在分類

student類

使用構(gòu)造方法初始化 get和set方法傳值

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;
 //對象數(shù)組初始化,使用構(gòu)造方法
 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;
 }


}

排序類
rank類

package swpu.student;

public class Rank {
 public static void rankscore(Student [] arr,int n){
 //數(shù)學(xué)
 if(n==1) {
 for (int i = 0; i < arr.length-1; i++) {
  int index = i;
  int j;
  // 找出最小值得元素下標(biāo)
  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;
  // 找出最小值得元素下標(biāo)
  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;
  }
 }
 //計(jì)算機(jī)
 if(n==3) {
 for (int i = 0; i < arr.length-1; i++) {
  int index = i;
  int j;
  // 找出最小值得元素下標(biāo)
  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;
  }
 }
 }
}

這里使用了靜態(tài)方法傳入成績的值

查找類
search類

package swpu.student;

public class Search {
 //書寫兩種方法(學(xué)號,姓名)

 public int StuNum(Student arr[] ,String y)//傳入數(shù)組,查找值 ,使用字符串的比較
 {
 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;
 }
}

主要類

Instudent類

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];
 //學(xué)生成績初始化 
 stu[0] = new Student("Jack","軟工 ","20183101",80,90,85);
 stu[1] = new Student("Rose","大數(shù)據(jù)","20183102",99,93,90);
 stu[2] = new Student("John","網(wǎng)安全","20183103",87,70,74);
 stu[3] = new Student("Andi","網(wǎng)工程","20183104",67,66,68);
 stu[4] = new Student("Mike","物聯(lián)網(wǎng)","20183105",56,90,55);
 //局部變量的初始化
 String nu1 = "";
 String na1 = "";
 String ma1 = "";
 int t1=0,t2=0,t3=0;
 System.out.println("-------------------學(xué)生成績管理系統(tǒng)------------------------");
 //輸入學(xué)生信息
 for(int i=0;i<stu.length;i++) {
 System.out.println("請輸入第"+(i+1)+"個(gè)學(xué)生的姓名,專業(yè),學(xué)號,數(shù)學(xué)成績,計(jì)算機(jī)成績,英語成績"); 
 na1 = in.next();//姓名
 ma1 = in.next();//專業(yè)
 nu1 = in.next();//學(xué)號
 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學(xué)號,2姓名");
 int p = in.nextInt();
 if(p==1) {
 //使用學(xué)號的方法進(jìn)行查找
 System.out.println("輸入您所需要查找的學(xué)生學(xué)號");
 String y = in.next();
 int x = search.StuNum(stu,y);
 if(x>=0)
 System.out.println("學(xué)號:"+stu[x].number+" 學(xué)生:"+stu[x].name+" 專業(yè):"+stu[x].major+" 數(shù)學(xué):"+stu[x].math+" 計(jì)算機(jī):"+stu[x].computer+" 英語:"+stu[x].english);
 else
 System.out.println("輸入的學(xué)生不存在");
 }
 if(p==2) {
 //使用姓名的方法進(jìn)行查找
 System.out.println("輸入您所需要查找的學(xué)生姓名");
 String thename = in.next();
 int w = search.StuNam(stu,thename);
 if(w>=0)
 System.out.println("學(xué)號:"+stu[w].number+" 學(xué)生:"+stu[w].name+" 專業(yè):"+stu[w].major+" 數(shù)學(xué):"+stu[w].math+" 計(jì)算機(jī):"+stu[w].computer+" 英語:"+stu[w].english);
 else
 System.out.println("輸入的學(xué)生不存在");
 }
 System.out.println("是否需要對單科成績進(jìn)行排名 [Y/N] 1 =yes,2=no");
 int op = in.nextInt();
 if(op==1) {
 //單科成績的排序(輸入所需要科目然后直接進(jìn)行排序)
 Rank rank = new Rank();//創(chuàng)建對象
 System.out.println("輸入所需要排序的成績編號 , 1:數(shù)學(xué),2:英語,3:計(jì)算機(jī)");
 int major = in.nextInt();
 rank.rankscore(stu,major);
 //輸出排序后的成績
 for(int i = 0;i < stu.length;i++) {
 System.out.println("學(xué)號:"+stu[i].number+" 學(xué)生:"+stu[i].name+" 專業(yè):"+stu[i].major+" 數(shù)學(xué):"+stu[i].math+" 計(jì)算機(jī):"+stu[i].computer+" 英語:"+stu[i].english);
 }
 }
 else {
 System.out.println("結(jié)束,退出系統(tǒng)");
 }
 }
 

}

其中使用構(gòu)造方法初始化的時(shí)已經(jīng)存入了值,因此在使用set方法輸入學(xué)生信息時(shí)其實(shí)是修改學(xué)生信息,在構(gòu)造方法初始化的時(shí)候可以不用那么復(fù)雜 可直接根據(jù)數(shù)據(jù)類型 例如:

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

注意 在聲明局部變量的時(shí)候一定要記住初始化,否則將值傳入數(shù)組的時(shí)候會出現(xiàn)報(bào)錯(cuò)

運(yùn)行截圖:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論