本文為大家分享了java實現學生成績錄入系統,供大家參考,具體內容如下
1.學生類,包括學生的姓名和各科成績
public class Score { public String name; public double EnglishGrade, MathGrade,phyicalGrade, chemicalGrade,biologicalGrade; Score() { } public Score(String name,double EnglishGrade, double MathGrade,double phyicalGrade, double chemicalGrade,double biologicalGrade){ this.name = name; this.EnglishGrade = EnglishGrade; this.MathGrade = MathGrade; this.phyicalGrade = phyicalGrade; this.chemicalGrade = chemicalGrade; this.biologicalGrade = biologicalGrade; } }
2.對學生類進行設置,包括設置查找等
package score; public class ScoreZip { Score[] S = new Score[5]; public void setData(Score name, int index) {//添加成績類到成績數組中 S[index] = name; } public Score[] getData() { //返回學生數組 return S; } public Score SerchData(String name) { //查找學生各科成績 for (int index = 0; index < S.length; index++) { if (name !=null && S[index] != null ) if (S[index].name.equals(name)){ return S[index]; } } return null; } }
3.學生成績錄入及學生成績清單
package score; import java.util.Scanner; public class ScoreZip2 { public static void main(String[] arr) { Scanner Sc = new Scanner(System.in); ScoreZip Sr = new ScoreZip(); for (int i = 0; i < 5; i++) { //這里定義長度為五的學生成績表 System.out.println("輸入學生姓名:"); String name = Sc.next(); if (name.equals("n")) { break; } System.out.println("英語分數:"); double English = Sc.nextDouble(); System.out.println("數學分數:"); double Math = Sc.nextDouble(); System.out.println("物理分數:"); double Physical = Sc.nextDouble(); System.out.println("化學分數:"); double Chemical = Sc.nextDouble(); System.out.println("生物分數:"); double Biology = Sc.nextDouble(); Score s = new Score(name, English,Math,Physical,Chemical,Biology); Sr.setData(s, i); } System.out.println("=========================================" + "學生成績表======================================"); System.out.println("姓名/t/t英語成績/t/t數學成績/t/t物理成績/t/t化學成績/t/t生物成績"); Score[] b = Sr.getData(); for (Score S : b) { if (S == null) { break; } System.out.println(S.name + "/t/t" + S.EnglishGrade+"/t/t"+S.MathGrade +"/t/t"+S.phyicalGrade+"/t/t"+S.chemicalGrade+"/t/t"+S.biologicalGrade); } System.out.println("是否查找學生成績? 是Y 否N"); String flag = Sc.next(); if(flag.equals("Y")){ System.out.println("輸入要查找的學生名:"); String name = Sc.next(); Score S = Sr.SerchData(name); if (S == null) { System.out.println("對不起,沒有此學生名"); } else { double mg = S.MathGrade; double eg = S.EnglishGrade; double pg = S.phyicalGrade; double cg= S.chemicalGrade; double bg = S.biologicalGrade; double submit = mg+eg+pg+cg+bg; System.out.println("要查找的學生為:" + name + "/n數學成績為:" + mg + "/n英語成績為:" + eg+ "/n物理成績為:" + pg+ "/n化學成績為:" + cg + "/n生物成績為:" + bg+ "/n總成績成績為:" + submit); } } } }
結果圖:
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VeVb武林網。
新聞熱點
疑難解答
圖片精選