有只熊463 2023-01-03 22:58 采纳率: 85.3%
浏览 26
已结题

或许有人解释一下这段代码吗?

应该是试卷选项的设计


public class Question {
    private String title;
    private String[] options = new String[4];
    private int[] scores = new int[4];
    private Integer answer;

    public Question(String[] data) {
        this.title = data[0];
        this.options[0] = data[1];
        this.options[1] = data[2];
        this.options[2] = data[3];
        this.options[3] = data[4];
        this.scores[0] = Integer.parseInt(data[5]);
        this.scores[1] = Integer.parseInt(data[6]);
        this.scores[2] = Integer.parseInt(data[7]);
        try {
            this.scores[3] = Integer.parseInt(data[8]);
        }catch (Exception e){
            System.out.println(title);
        }
    }

    @Override
    public String toString() {
        return title + " " + options[0] + " " + options[1] + " " + options[2] + " " + options[3] + " "
                + scores[0] + " " + scores[1] + " " + scores[2] + " " + scores[3];
    }

    public void setOptions(String[] options) {
        this.options = options;
    }

    public void setScores(String[] scores) {
        this.scores[0] = Integer.parseInt(scores[0]);
        this.scores[1] = Integer.parseInt(scores[1]);
        this.scores[2] = Integer.parseInt(scores[2]);
        this.scores[3] = Integer.parseInt(scores[3]);
    }

    public String getTitle() {
        return title;
    }

    public void setAnswer(int answer) {
        this.answer = answer;
    }

    public String getOptions(){
        return "A." + options[0] + " B." + options[1] + " C." + options[2] + " D." + options[3];
    }

    public String getOption(int index){
        switch (index){
            case 0:return "A." + options[index];
            case 1:return "B." + options[index];
            case 2:return "C." + options[index];
            case 3:return "D." + options[index];
        }
        return null;
    }

    public int getScore(){
        if (answer != null){
            return scores[answer];
        }
        return -1;
    }
}

  • 写回答

1条回答 默认 最新

  • ShowMeAI 2023-01-03 23:36
    关注

    这是一个表示试卷中的一道选择题的类。

    该类有以下几个属性:

    • title:表示该题的标题。
    • options:表示该题的四个选项,题号分别为 A、B、C、D。
    • scores:表示该题的四个选项的分数。
    • answer:表示该题的正确答案,使用题号表示,A 对应 0,B 对应 1,C 对应 2,D 对应 3。

    该类有以下几个方法:

    • Question:构造方法,用于初始化该类的属性。
    • toString:返回一个表示该题目的字符串。
    • setOptions:用于设置该题的四个选项。
    • setScores:用于设置该题四个选项的分数。
    • getTitle:返回该题的标题。
    • setAnswer:用于设置该题的正确答案。
    • getOptions:返回该题的四个选项。
    • getOption:返回该题的某个选项。
    • getScore:返回该题的正确答案的分数。

    这些方法和属性共同构成了一个表示试卷中的一道选择题的类。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 1月11日
  • 已采纳回答 1月3日
  • 修改了问题 1月3日
  • 创建了问题 1月3日

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分