欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

java实现学生成绩录入系统

程序员文章站 2023-12-11 16:00:23
本文为大家分享了java实现学生成绩录入系统,供大家参考,具体内容如下 1.学生类,包括学生的姓名和各科成绩 public class score {...

本文为大家分享了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); 
       } 
    } 
  } 
} 


结果图:

java实现学生成绩录入系统

java实现学生成绩录入系统

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

上一篇:

下一篇: