一、考试成绩统计
1、功能要求
开发基于控制台的考试成绩统计系统。具体要求如下:
(1)接受用户输入的5组姓名和分数。
(2)统计并打印平均分。
(3)统计并打印分数低于60分的姓名和分数。 系统运行界面
2、类的设计
该系统包含2个类Student和Test。
3、具体要求及推荐实现步骤
1)编写Student类,包含2个属性:name和score。(10分)
2)编写Test类,添加main()方法,在方法中声明并实例化Student类型的数组students。(20分)
3)循环接收用户输入的数据(25分)
4)统计并打印平均成绩(10分)
5)查找并打印不及格的学生及分数(30分)
编码规范:5分

解决方案 »

  1.   

    package 成绩管理系统;public class Student {
    public String name;
    public int score;
    /*private void setName(String name){
    this.name = name;
    }
    private void setScore(int score){
    this.score = score;
    }*/
    }package 小学生成绩管理系统;import java.util.Scanner;public class Primaryscholar_ScoreManageSystem { public        static void main(String[] args) {
    Student[] students = new Student[5];
    String[] name = new String[5];
       int[] score = new int[5];
    Scanner scanner = new Scanner(System.in);   for(int i = 0; i < students.length;i++){
    students[i] = new Student(); System.out.print("请输入第"  + (i + 1) + "个学生的姓名和成绩:");
    students[i].name = scanner.next();
    name[i] = students[i].name;         students[i].score = scanner.nextInt();
    score[i] = students[i].score;
    }
    Primaryscholar_ScoreManageSystem ps = new Primaryscholar_ScoreManageSystem(); ps.scorePrint(name, score); System.out.println();
    ps.scoreSort(name,score);
    System.out.println();
    double average = ps.averageScore(score); System.out.println("平均成绩是:" + average);
    ps.binarySearch(name, score); scanner.close();
    }
    //求平均成绩
    private double averageScore(int[] score){
    double sum = 0;
    for(int i = 0; i < score.length; i++){ sum += (double)score[i];
    }
    return sum / score.length;
    }
    //成绩打印
    private void scorePrint(String[] name, int [] score){
    for(int i = 0; i < name.length; i++){ System.out.println(name[i] +"\t" + score[i]);
    }
    }
    //不及格成绩查询
    private void  binarySearch(String[] name, int[] score){
    int count = 0;
    for(int x : score){ 
    if(x < 60){ count++;
         }
    }
    int []index = new int[count];
    int j = 0;
    for(int i = 0; i < score.length; i++){ if(score[i] < 60){
    index[j] = i;
    j++;
    }
    }
    System.out.println("不及格的学生是:");
    for(int k = 0; k < index.length; k++){ System.out.println(name[index[k]] +"\t" + score[index[k]]);
    }
    }
    //成绩排序
    private void scoreSort(String[] name, int[] score){ for(int i = 0; i < score.length-1; i++){
    for(int j = 0; j < score.length-1-i; j++){ if(score[j] < score[j + 1]){
    int temp = score[j];
    String str = name[j];
    score[j] = score[j + 1];
    name[j] = name[j + 1];
    score[j +1] = temp;
    name[j + 1] = str;
    }
    }
    }
    for(int i = 0; i < name.length; i++){ System.out.println(name[i] +"\t" + score[i]); } } }