JAVA之学生信息
定義一個Student數組,其中保存學生的基本信息,包括姓名,學號,性別,還分別保存三門課程的成績和對應學分。試編程計算這三門課程的學分積,并按學分積的降冪進行排序,輸出排序后的結果。
public class Student { /**成員變量:姓名,學號,性別,數學,英語,語文,數學學分,英語學分,語文學分,三門課程學分積附加:按學分積降冪進行排序,輸出結果*/public float Math;//數學public float English;//英語public float Chinese;//語文public int MathCredit;//數學學分public int EnglishCredit;//英語學分public int ChineseCredit;//語文學分public float product;//學分積public String name;public String Id;public String sex;public static void main(String[] args) {//初始化數組 Student stu1=new Student(); {stu1.name="**";stu1.Id="***";stu1.sex="男";stu1.Math=70;stu1.MathCredit=5;stu1.English=73;stu1.EnglishCredit=4;stu1.Chinese=83;stu1.ChineseCredit=3;stu1.product=stu1.Math*stu1.MathCredit+stu1.English*stu1.EnglishCredit+stu1.Chinese*stu1.ChineseCredit;System.out.println("姓名 "+stu1.name);System.out.println("學號 "+stu1.Id);System.out.println("性別 "+stu1.sex);System.out.println("數學成績 "+stu1.Math);System.out.println("數學學分 "+stu1.MathCredit);System.out.println("英語成績 "+stu1.English);System.out.println("英語學分 "+stu1.EnglishCredit);System.out.println("物理成績 "+stu1.Chinese);System.out.println("物理學分 "+stu1.ChineseCredit);System.out.println("學分積 "+stu1.product);}Student stu2=new Student();{stu2.name="***";stu2.Id="201730134002";stu2.sex="男";stu2.Math=73;stu2.MathCredit=5;stu2.English=72;stu2.EnglishCredit=4;stu2.Chinese=78;stu2.ChineseCredit=3;stu2.product=stu2.Math*stu2.MathCredit+stu2.English*stu2.EnglishCredit+stu2.Chinese*stu2.ChineseCredit;System.out.println("姓名 "+stu2.name);System.out.println("學號 "+stu2.Id);System.out.println("性別 "+stu2.sex);System.out.println("數學成績 "+stu2.Math);System.out.println("數學學分 "+stu2.MathCredit);System.out.println("英語成績 "+stu2.English);System.out.println("英語學分 "+stu2.EnglishCredit);System.out.println("物理成績 "+stu2.Chinese);System.out.println("物理學分 "+stu2.ChineseCredit);System.out.println("學分積 "+stu2.product);}Student stu3=new Student();{stu3.name=***";stu3.Id="201730134031";stu3.sex="女";stu3.Math=75;stu3.MathCredit=5;stu3.English=85;stu3.EnglishCredit=4;stu3.Chinese=86;stu3.ChineseCredit=3;stu3.product=stu3.Math*stu3.MathCredit+stu3.English*stu3.EnglishCredit+stu3.Chinese*stu3.ChineseCredit;System.out.println("姓名 "+stu3.name);System.out.println("學號 "+stu3.Id);System.out.println("性別 "+stu3.sex);System.out.println("數學成績 "+stu3.Math);System.out.println("數學學分 "+stu3.MathCredit);System.out.println("英語成績 "+stu3.English);System.out.println("英語學分 "+stu3.EnglishCredit);System.out.println("物理成績 "+stu3.Chinese);System.out.println("物理學分 "+stu3.ChineseCredit);System.out.println("學分積 "+stu3.product);}Student stu4=new Student();{stu4.name="***";stu4.Id="201730134047";stu4.sex="男";stu4.Math=90;stu4.MathCredit=5;stu4.English=90;stu4.EnglishCredit=4;stu4.Chinese=86;stu4.ChineseCredit=3;stu4.product=stu4.Math*stu4.MathCredit+stu4.English*stu4.EnglishCredit+stu4.Chinese*stu4.ChineseCredit;System.out.println("姓名 "+stu4.name);System.out.println("學號 "+stu4.Id);System.out.println("性別 "+stu4.sex);System.out.println("數學成績 "+stu4.Math);System.out.println("數學學分 "+stu4.MathCredit);System.out.println("英語成績 "+stu4.English);System.out.println("英語學分 "+stu4.EnglishCredit);System.out.println("物理成績 "+stu4.Chinese);System.out.println("物理學分 "+stu4.ChineseCredit);System.out.println("學分積 "+stu4.product);}System.out.print("學分積依次為:"+stu1.product+" "+stu2.product+" "+stu3.product+" "+stu4.product);Student students[]=new Student[4];{students[0]=stu1;students[1]=stu2;students[2]=stu3;students[3]=stu4;}System.out.println("學分積降冪排序為:"+"\n");for(int i=0;i<students.length;i++) {for(int j=i;j<students.length;j++) {if(students[i].product<students[j].product){float temp=0;temp=students[i].product;students[i].product=students[j].product;students[j].product=temp;} }System.out.println("學分積降冪排序的結果為:"+students[i].product);}} } 《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
- 上一篇: JAVA之统计
- 下一篇: 快速傅里叶变化(周期信号)