您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
本文为大家分享了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); } } } }
结果图:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持亿速云。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。