zoukankan      html  css  js  c++  java
  • 大赛评分应用程序

    //2007年04月30日晚上凌晨左右以记事本抄写自某java教材。

    //想起那时候刚开始学java,一个classpath就能折磨我好几天。呵。

    package pingfen;

    //负责程序运行入口和调用其他类,并建立主循环,等待用户操作。
    import java.io.*;
    public class Program {
     public static void main(String[] args) throws IOException {
      BufferedReader input = new BufferedReader(new InputStreamReader(
        System.in));
      String inputString = "0";
      Register register = new Register();
      Grade grade = new Grade();
      System.out.println("欢迎使用大赛平分程序");
      System.out.println("-----选手检录-----");
      register.registing();// 选手检录
      // 进入主循环,等待用户选择操作
      do {
       System.out.println("评委打分请按1,查看成绩请按2,退出请按0");
       inputString = input.readLine();
       if (inputString.equals("1")) {
        grade.grading(register.returnCandidate());// 评委打分
       }
       if (inputString.equals("2")) {
        grade.showMark(register.returnCandidate());// 查看成绩
       }
      } while (!inputString.equals("0")); // 退出
     }
    }

    package pingfen;

    //选手对象,负责保存选手和分数信息。
    public class Candidate {
     public int ID;
     public String name;
     public double mark;
     public double[] marks;

     public Candidate(int id, String nam) {
      this.ID = id;
      this.name = nam;
      this.marks = new double[6];
     }

     public String toString() {
      return ID + "号选手  姓名:" + name + " 总分:" + mark;
     }
    }

    package pingfen;

    //检录对象,负责创建和管理多个选手对象。
    import java.io.*;

    public class Register {
     public Candidate[] candidates;
     String inputString;

     public void registing() throws IOException {
      System.out.println("请输入参赛人数,退出按0");
      BufferedReader input = new BufferedReader(new InputStreamReader(
        System.in));
      inputString = input.readLine();
      int n = Integer.parseInt(inputString);
      if (n != 0) {
       candidates = new Candidate[n + 1];
       for (int i = 1; i <= n; i++) {
        System.out.println("请输入" + i + "号参赛选手姓名:");
        inputString = input.readLine();
        Candidate candidate = new Candidate(i, inputString);
        candidates[i] = candidate;
       }
      }
     }

     public Candidate[] returnCandidate() {
      return candidates;
     }
    }

    package pingfen;

    //创建记分对象,负责评委对选手打分,记分统计,分数显示。
    import java.io.*;

    public class Grade {
     BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
     String inputString;

     // 去掉一个最高分,去掉一个最低分,求出平均分作为选手最后得分
     public double calculateMark(double[] marks) {
      double max = 0.0; // 将最大值初始化为0
      double min = 100.0; // 将最小值初始化为100
      double total = 0.0;
      for (int i = 1; i <= 5; i++) {
       if (marks[i] < min)
        min = marks[i];
       if (marks[i] > max)
        max = marks[i];
       total = total + marks[i];
      }
      total = (total - max - min) / 3.0;
      System.out.println("去掉一个最高分" + max + ",去掉一个最低分" + min + ",该选手最后得分:"
        + total);
      return total;
     }

     // 评委打分
     public void inputMarks(double[] marks) throws IOException {
      for (int i = 1; i <= 5; i++) {
       System.out.println(i + "号评委打分");
       inputString = input.readLine();
       double m = Double.parseDouble(inputString);
       marks[i] = m;
      }
     }

     // 排序
     public void sort(Candidate[] c, int key) {
      Candidate tmp;
      boolean changed = false;
      for (int i = 1; i <= (c.length - 1); i++) {
       for (int j = 1; j <= ((c.length - 1) - 1); j++) {
        if (key == 1)
         changed = (c[j].ID > c[j + 1].ID);// 按选手编号排序
        if (key == 2)
         changed = (c[j].mark < c[j + 1].mark);// 按选手成绩排序
        if (changed) {
         tmp = c[j];
         c[j] = c[j + 1];
         c[j + 1] = tmp;
        }
       }
      }
     }

     // 显示成绩
     public void showMark(Candidate[] c) throws IOException {
      System.out.println("-----选手成绩-----");
      System.out.println("按选手编号排序请按1,按选手成绩排序请按2");
      inputString = input.readLine();
      int n = Integer.parseInt(inputString);
      sort(c, n);
      for (int i = 1; i <= (c.length - 1); i++) {
       System.out.println(c[i].toString());
      }
     }

     // 求选手最后得分
     public void grading(Candidate[] c) throws IOException {
      System.out.println("-----评委打分-----");
      for (int i = 1; i <= (c.length - 1); i++) {
       System.out.println("给" + i + "号选手打分:");
       inputMarks(c[i].marks);
       c[i].mark = calculateMark(c[i].marks);
      }
     }
    }

  • 相关阅读:
    手机app数据的爬取之mitmproxy安装教程
    Scrapy库的安装(windows版)
    Cannot uninstall 'html5lib'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
    HTTP 599: SSL certificate problem: unable to get local issuer certificate错误
    requests禁止重定向
    python多线程爬取-今日头条的街拍数据(附源码加思路注释)
    python爬虫-淘宝商品密码(图文教程附源码)
    20131214-HTML基础-第二十一天
    20131214-EditPlus快捷键-第二十一天
    20131209-数据库导入导出数据-sqlhelper-第十七天
  • 原文地址:https://www.cnblogs.com/chaohi/p/2330373.html
Copyright © 2011-2022 走看看