最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

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

要求:

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

首先先創(chuàng)建一個student類
使用構(gòu)造方法來初始化
學號、姓名、年級、專業(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ù)學
 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;
  }
 }
 }
}

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

查找類
search類

package swpu.student;

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

 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];
 //學生成績初始化 
 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("-------------------學生成績管理系統(tǒng)------------------------");
 //輸入學生信息
 for(int i=0;i<stu.length;i++) {
 System.out.println("請輸入第"+(i+1)+"個學生的姓名,專業(yè),學號,數(shù)學成績,計算機成績,英語成績"); 
 na1 = in.next();//姓名
 ma1 = in.next();//專業(yè)
 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+" 專業(yè):"+stu[x].major+" 數(shù)學:"+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+" 專業(yè):"+stu[w].major+" 數(shù)學:"+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();//創(chuàng)建對象
 System.out.println("輸入所需要排序的成績編號 , 1:數(shù)學,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+" 專業(yè):"+stu[i].major+" 數(shù)學:"+stu[i].math+" 計算機:"+stu[i].computer+" 英語:"+stu[i].english);
 }
 }
 else {
 System.out.println("結(jié)束,退出系統(tǒng)");
 }
 }
 

}

其中使用構(gòu)造方法初始化的時已經(jīng)存入了值,因此在使用set方法輸入學生信息時其實是修改學生信息,在構(gòu)造方法初始化的時候可以不用那么復(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ù)組的時候會出現(xiàn)報錯

運行截圖:

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

相關(guān)文章

  • java static塊和構(gòu)造函數(shù)的實例詳解

    java static塊和構(gòu)造函數(shù)的實例詳解

    這篇文章主要介紹了java static塊和構(gòu)造函數(shù)的實例詳解的相關(guān)資料,希望通過本文能幫助到大家,讓大家理解掌握Java static關(guān)鍵字的函數(shù)方法,需要的朋友可以參考下
    2017-09-09
  • Springboot的Mapper中添加新的SQL語句方法詳解

    Springboot的Mapper中添加新的SQL語句方法詳解

    在如今的軟件開發(fā)界,Spring Boot可是非常受歡迎的框架哦,尤其是在微服務(wù)和RESTful API的構(gòu)建上,下面給大家介紹我們?nèi)绾螢镾pring Boot項目中的Mapper添加新的SQL語句吧,感興趣的朋友一起看看吧
    2025-04-04
  • RestTemplate Get請求實現(xiàn)bean參數(shù)傳遞詳解

    RestTemplate Get請求實現(xiàn)bean參數(shù)傳遞詳解

    RestTemplate 是從 Spring3.0 開始支持的一個 HTTP 請求工具,也有的稱之為網(wǎng)絡(luò)框架,說白了就是Java版本的一個postman,這篇文章主要介紹了詳解RestTemplate 用法,需要的朋友可以參考下
    2022-11-11
  • SpringBoot3配置Logback日志滾動文件的方法

    SpringBoot3配置Logback日志滾動文件的方法

    本文介紹了在SpringBoot3中配置Logback日志滾動文件的方法,因為SpringBoot3內(nèi)置的logback版本是1.4.14,之前使用SpringBoot2.1.5的logback配置發(fā)現(xiàn)有些東西不能生效了,需要的朋友可以參考下
    2024-08-08
  • 探討:如何在NDK中呼叫Java的class

    探討:如何在NDK中呼叫Java的class

    本篇文章是對如何在NDK中呼叫Java的class進行了詳細的分析介紹,需要的朋友參考下
    2013-05-05
  • java組件commons-fileupload實現(xiàn)文件上傳、下載、在線打開

    java組件commons-fileupload實現(xiàn)文件上傳、下載、在線打開

    這篇文章主要介紹了java組件commons-fileupload實現(xiàn)文件上傳、下載、在線打開,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-10-10
  • springboot整合@Retryable實現(xiàn)重試功能的示例代碼

    springboot整合@Retryable實現(xiàn)重試功能的示例代碼

    本文主要介紹了springboot整合@Retryable實現(xiàn)重試功能的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-05-05
  • 解決spirngboot連接redis報錯:READONLY?You?can‘t?write?against?a?read?only?replica的問題

    解決spirngboot連接redis報錯:READONLY?You?can‘t?write?against?

    docker部署的redis,springboot基本每天來連redis都報錯:READONLY?You?can't?write?against?a?read?only?replica,重啟redis后,可以正常連接。但是每天都重啟redis,不現(xiàn)實,也很麻煩,今天給大家分享解決方式,感興趣的朋友一起看看吧
    2023-06-06
  • Java設(shè)計模式之java中介者模式詳解

    Java設(shè)計模式之java中介者模式詳解

    這篇文章主要為大家詳細介紹了23種設(shè)計模式之java中介者模式,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2021-09-09
  • 使用Spring Data R2DBC +Postgres實現(xiàn)增刪改查功能

    使用Spring Data R2DBC +Postgres實現(xiàn)增刪改查功能

    這篇文章主要介紹了使用Spring Data R2DBC +Postgres實現(xiàn)增刪改查功能,本文通過兩種方法給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-03-03

最新評論

吴堡县| 宁都县| 乌拉特中旗| 齐河县| 同心县| 壶关县| 台前县| 涡阳县| 镇巴县| 来宾市| 阿图什市| 汾西县| 大港区| 辛集市| 厦门市| 遵义县| 邛崃市| 永善县| 靖安县| 如皋市| 克拉玛依市| 和硕县| 台江县| 萝北县| 达日县| 钟祥市| 壶关县| 茶陵县| 沙田区| 上栗县| 宣威市| 兖州市| 桓仁| 贵溪市| 仁寿县| 甘南县| 淮阳县| 宜兰市| 上高县| 怀集县| 昔阳县|