中国计算机设计大赛赛事统计

本文介绍如何设计一个统计计算机设计大赛成绩的程序,包括处理各学校的总分、项目获奖情况,以及数据的存储和查询。文章讨论了设计要求、数据结构选择,如考虑使用Java的结构体,以及面临的问题和解决方案。内容涵盖菜单交互设计、数据存储和测试数据的处理。
摘要由CSDN通过智能技术生成

目录

【问题描述】

【基本要求】

【设计要求】

【测试数据】

【实现提示】

【初步思考】

【流程图】

 【实现代码】


【问题描述】

参加计算机设计大赛的n个学校编号为1~n,赛事分成m个项目,项目的编号为1~m.比赛获奖按照得分降序,取前三名,写一个统计程序产生各种成绩单和得分报表。

【基本要求】

  1. 每个比赛项目至少有10支参赛队;每个学校最多有6支队伍参赛;

  2. 能统计各学校的总分;

  3. 可以按照学校编号或名称,学校的总分、各项目的总分排序输出;

  4. 可以按学校编号查询学校某个项目的获奖情况;可以按项目编号查询取得前三名的学校;

  5. 数据存入文件并能随时查询

【设计要求】

  1. 输入数据形式和范围:可以输入学校的名称,赛事项目的名称。

  2. 输出形式:有中文提示,各学校分数为整数

  3. 界面要求:交互设计要合理,每个功能可以设立菜单,根据提示,可以完成相关功能的要求。

  4. 存储结构:学生自己根据系统功能要求自己设计,但是赛事相关数据要存储在文件中。

【测试数据】

要求使用全部合法数据,整体非法数据,局部非法数据。进行程序测试,以保证程序的稳定。

【实现提示】

假设3<赛事项目数量<=10,学校名称长度不超过20个字符。每个赛事结束时,将其编号、名称输入,并依次输入参赛学校编号、学校名称和成绩。

【初步思考】

        从交互性来看,为了更好的参与感,我首先编写了一个菜单栏,使用者可以通过键入选择想要进行的操作。一开始本来想要使用列表和数组来写,但是貌似有些不兼容,并且二者对应起来十分的麻烦,我的朋友向我推荐了C++里面的结构体,但是对我而言还是Java更加的熟悉,奈何Java的结构体不是很了解,故先搁置。
        我慢慢的搞清楚了一些Java的结构体的用法,值得注意的是使用的时候要创建对象。然后就有一个新的问题出现,那就是应该怎么定义?或者说定义几个结构体。如果我以项目为基本单位,以"项目编号,项目名称,参加项目的学校的编号,参加项目学校的名称,该学校取得的分数"这样写,那么单项目总分和学校排名以及取前三名将会变得非常简单,但是这样的话我就需要思考的是学校总分如何去计算

【流程图】

 【实现代码】

import java.util.*;
 
public class test {
    static int m;
    //项目数
    static int n;
    //学校数
    static Project[] project = new Project[10];
    //项目
    static School[] school = new School[10];
    //学校
 
 
    static class Project {
        int projectCode;
        //项目编码
        String projectName;
        //项目名称
        int teamnum;
        //参赛队伍数量
        int[] jointeam = new int[10];
        //参赛队伍编号
        int[] score = new int[10];
        //参赛队伍成绩
    }
 
    static class School {
        int schoolCode;
        //学校编码
        String schoolName;
        //学校名称
        int sum;
        //项目总分
    }
 
    public static void main(String[] args) {
 
        Scanner sc = new Scanner(System.in);
 
        System.out.println("请输入项目的数目:");
        m = sc.nextInt();
        if (m <= 0) {
            System.out.println("输入有误!");
            System.exit(0);
        }
        System.out.println("请输入学校的数目:");
        n = sc.nextInt();
        if (n <= 0) {
            System.out.println("输入有误!");
            System.exit(0);
        }
        while (true) {
            System.out.println("**********************");
            System.out.println("欢迎使用赛事统计查询系统");
            System.out.println("1.添加信息");
            System.out.println("2.按学校编号排序输出");
            System.out.println("3.按项目总分排序输出");
            System.out.println("4.按学校编号查询学校某个项目的获奖情况");
            System.out.println("5.按项目编号查询取得前三名的学校");
            System.out.println("0.退出");
            System.out.println("**********************");
            System.out.println("请输入你的选择:");
 
            String nothing = sc.nextLine();    //防止空格
            int option = sc.nextInt();
            if (option != 0 && option != 1 && option != 2 && option != 3 && option != 4 && option != 5) {
                System.out.println("输入有误!");
                System.exit(0);
            }
 
            switch (option) {
                case 1:
                    addInformation();
                    break;
                case 2:
                    printByCodes();
                    break;
                case 3:
                    printByScore();
                    break;
                case 4:
                    findByCodes();
                    break;
                case 5:
                    getTopThree();
                    break;
                case 0:
                    System.out.println("谢谢使用");
                    System.exit(0);
            }
        }
    }
 
    public static void addInformation() {
        //录入信息
        //录入项目
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < m; i++) {
            project[i] = new Project();
            project[i].projectCode = i + 1;
            System.out.println("请输入第" + (i + 1) + "个项目的名称:");
            project[i].projectName = sc.nextLine();
            System.out.println("添加成功!");
        }
        for (int i = 0; i < m; i++) {
            System.out.println("项目编号" + project[i].projectCode +
                    "项目名称" + project[i].projectName);
        }
        //录入学校
        for (int i = 0; i < n; i++) {
            school[i] = new School();
            school[i].schoolCode = i + 1;
            System.out.println("请输入第" + (i + 1) + "个学校的名称:");
            school[i].schoolName = sc.nextLine();
            System.out.println("添加成功!");
        }
        for (int i = 0; i < n; i++) {
            System.out.println("学校编号" + school[i].schoolCode +
                    "学校名称" + school[i].schoolName);
        }
        for (int i = 0; i < m; i++) {
            System.out.println("请输入参加" + project[i].projectName + "的学校数量:");
            project[i].teamnum = sc.nextInt();
            System.out.println("请依次输入参加" + project[i].projectName + "的学校编号:");
            for (int j = 0; j < project[i].teamnum; j++) {
                project[i].jointeam[j] = sc.nextInt();
                System.out.println("输入成功!");
            }
            System.out.println("参加项目" + project[i].projectName + "的学校有");
            for (int j = 0; j < project[i].teamnum; j++) {
                System.out.println(project[i].jointeam[j] + " ");
            }
            //录入分数
            System.out.println("请依次输入参加" + project[i].projectName + "的学校的分数");
            for (int j = 0; j < project[i].teamnum; j++) {
                int score = sc.nextInt();
                if (score >= 0 && score <= 100) {
                    project[i].score[j] = score;
                    System.out.println("输入成功!");
                } else {
                    System.out.println("您输入的有误!");
                    System.exit(0);
                }
            }
            System.out.println("显示如下:");
            for (int j = 0; j < project[i].teamnum; j++) {
                System.out.println("编号" + project[i].jointeam[j] + "的学校取得的成绩:" + project[i].score[j]);
            }
        }
    }
 
    public static void printByCodes() {
        //按学校编号排序输出
        int sum = 0;
        for (int i = 0; i < n; i++) {
            System.out.println("学校编号:" + school[i].schoolCode);
            System.out.println("学校名称:" + school[i].schoolName);
            for (int j = 0; j < m; j++) {
                for (int k = 0; k < project[j].jointeam[k]; k++) {
                    if (project[j].jointeam[k] == school[i].schoolCode) {
                        System.out.println("参赛项目:" + project[j].projectName);
                        System.out.println("取得成绩:" + project[j].score[k]);
                        System.out.println("*****");
                        sum += project[j].score[k];
                    }
                }
            }
            System.out.println("学校取得的总分是:" + sum);
            school[i].sum = sum;
            sum = 0;
            System.out.println("**********************");
        }
    }
 
    public static void printByScore() {
        //按总分排序
        int temp = 0;
        int[] temps = new int[n];
        for (int i = 0; i < n; i++) {
            temps[i] = school[i].sum;
        }
        for (int i = 0; i < n; i++) {
            for (int j = i; j < n; j++) {
                if (temps[i] > temps[j]) {
                    temp = temps[i];
                    temps[i] = temps[j];
                    temps[j] = temp;
                }
            }
        }
        System.out.println("按照总分排序学校如下:");
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (temps[i] == school[j].sum) {
                    System.out.println("总分第" + (n - i) + "名的学校是" + school[j].schoolName);
                    System.out.println("其总分是:" + school[j].sum);
                    System.out.println("*******");
                }
            }
        }
    }
 
    public static void findByCodes() {
        //按学校编号查询学校某个项目的获奖情况
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入你想要查询的学校编号");
        int scode = sc.nextInt();
        System.out.println("请输入你想要查询的项目编号");
        int pcode = sc.nextInt();
 
        int[] temps = new int[project[pcode - 1].teamnum];
        int len = temps.length;
        for (int i = 0; i < len; i++) {
            temps[i] = project[pcode - 1].score[i];
        }
        int temp = 0;
        for (int i = 0; i < len; i++) {
            for (int j = i; j < len; j++) {
                if (temps[i] > temps[j]) {
                    temp = temps[i];
                    temps[i] = temps[j];
                    temps[j] = temp;
                }
            }
        }
        for (int i = 0; i < len; i++) {
            for (int j = 0; j < len; j++) {
                if (project[pcode - 1].score[i] == temps[j]) {
                    System.out.println("该学校在该项目中排第" + j + "名");
                }
            }
        }
    }
 
    public static void getTopThree() {
        //按项目编号查询取得前三名的学校
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入您想要查询的项目的编号:");
        int code = sc.nextInt();
        int[] temps = new int[project[code - 1].teamnum];
        int len = temps.length;
        for (int i = 0; i < len; i++) {
            temps[i] = project[code - 1].score[i];
        }
        int temp = 0;
        for (int i = 0; i < len; i++) {
            for (int j = i; j < len; j++) {
                if (temps[i] > temps[j]) {
                    temp = temps[i];
                    temps[i] = temps[j];
                    temps[j] = temp;
                }
            }
        }
        for (int i = 0; i < len; i++) {
            for (int j = 0; j < n; j++) {
                if (temps[len - 1] == project[code - 1].score[i]) {
                    if (school[j].schoolCode == project[code - 1].jointeam[i]) {
                        System.out.println("第一名的学校是:" + school[j].schoolName);
                    }
                }
                if (temps[len - 2] == project[code - 1].score[i]) {
                    if (school[j].schoolCode == project[code - 1].jointeam[i]) {
                        System.out.println("第二名的学校是:" + school[j].schoolName);
                    }
                }
                if (temps[len - 3] == project[code - 1].score[i]) {
                    if (school[j].schoolCode == project[code - 1].jointeam[i]) {
                        System.out.println("第三名的学校是:" + school[j].schoolName);
                    }
                }
            }
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值