24小时热门版块排行榜    

北京石油化工学院2026年研究生招生接收调剂公告
查看: 1701  |  回复: 17

茶家美 Aimee

版主

优秀!!有木有!!!优秀!!有木有!!!优秀!!有木有!!!优秀!!有木有!!!

[交流] 能帮我解决小学生测验编程不? 已有12人参与

能帮我看看这个编程题不?谢谢啦

能帮我解决小学生测验编程不?


发自小木虫Android客户端
回复此楼

» 猜你喜欢

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
回帖支持 ( 显示支持度最高的前 50 名 )

ioadong

专家顾问

优秀!!有木有!!!优秀!!有木有!!!优秀!!有木有!!!优秀!!有木有!!!

★ ★ ★
小木虫: 金币+0.5, 给个红包,谢谢回帖
jjdg: 金币+2, 说的很对 2017-05-19 22:33:49
忍不住,还是要说下,现实中没有人喜欢你这种一点点自己的想法都没有,直接伸手要答案的。
你真心想找人帮忙也应该自己拿出点可以讨论的东西出来。空手而来只会空手而去。
以科学的理性代替天然的非理性。
4楼2017-05-19 08:54:09
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

lbstorm

超级版主

优秀!!有木有!!!优秀!!有木有!!!优秀!!有木有!!!优秀!!有木有!!!

★ ★ ★
小木虫: 金币+0.5, 给个红包,谢谢回帖
jjdg: 金币+2, 辛苦了 2017-05-19 22:34:14
//一共三个java类。写得不好,不足的地方欢迎指正。
// 1.
package com.test.muchong.pupil;

import java.util.Scanner;

/**
* Created by Lieber on 2017/5/19.
*/
public class Check {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int totalScore = 0;
        int questions = 10;
        int answer = 0;

        for (int i = 0; i < questions; i++) {
            int times = 3;
            Question question = new Question();
            DisplayResult.showEquation(question.getEquation());
            DisplayResult.showInput();
            answer = scanner.nextInt();
            boolean flag = false;
            while (! flag) {
                if (times <=3 && times > 1) {
                    flag = question.check(answer);
                    if (!flag) {
                        times--;
                        DisplayResult.showError(times);
                        answer = scanner.nextInt();
                    }
                } else {
                    DisplayResult.showRightAnswer(question.getResult());
                    break;
                }
            }
            totalScore += Check.score(times);

        }
        DisplayResult.showTotalScore(totalScore);

    }

    public static int score(int sco) {
        int result = 0;
        switch (sco) {
            case 3:
                result = 10;
                break;
            case 2:
                result = 7;
                break;
            case 1:
                result = 5;
                break;
            default:
                result = 0;
                break;
        }
        return result;
    }
}


//2.
package com.test.muchong.pupil;

import java.util.Random;

/**
* Created by Lieber on 2017/5/19.
*
* 每一道题:
* 1,生成公式。
* 2,接受输入
* 3,检查结果
* 4,
*/


public class Question {
    private int numberOne;
    private int numberTwo;
    private enum  Symbol { plus, minus};
    private int result;

    private static Random random = new Random();
    private Symbol symbol;

    /**
     * 生成随机整数 (0至50)
     * @return int
     */
    public int getRandomNumber() {
        int number = Math.abs(random.nextInt() % 50);
        return number;
    }


    public void setRandomSymbol() {
        this.symbol = Question.getRandomEnum(Symbol.class);
    }

    /**
     * 生成随机数
     */
    public void init() {
        numberOne = getRandomNumber();
        numberTwo = getRandomNumber();
    }

    public String getEquation() {
        boolean flag = true;
        while (flag) {
            init();
            setRandomSymbol();
            if (symbol.equals(Symbol.plus)) {
                this.result = numberOne + numberTwo;
                if (result > 50) {
                    flag = true;
                } else {
                    flag = false;
                }
            } else {
                this.result = numberOne - numberTwo;
                if ( result> 0 && result < 50) {
                    flag = false;
                } else {
                    flag = true;
                }
            }
        }
        return getString();
    }

    /**
     * 获取公式的表达式
     * @return String
     */
    public String getString() {
        if (symbol.equals(Symbol.plus)) {
            String temp = numberOne + " + " + numberTwo + " = ";
            return temp;
        } else {
            String temp = numberOne + " - " + numberTwo + " = ";
            return temp;
        }
    }

    /**
     * 生成随机符 +号或-号
     */
    public static <T extends Enum<?>> T getRandomEnum(Class<T> clazz) {
        int x = random.nextInt(clazz.getEnumConstants().length);
        return clazz.getEnumConstants()[x];
    }

    /**
     * 获取正确答案
     * @return
     */
    public int getResult() {
        return this.result;
    }

    /**
     * 检查输入
     * @param answer
     * @return
     */
    public boolean check(int answer) {
        if (answer == result) {
            return true;
        } else {
            return false;
        }
    }
}

//3.

package com.test.muchong.pupil;

/**
* Created by Lieber on 2017/5/19.
*
* 显示输出结果:
* 1,输出错误时,提示重新输入
* 2,三次机会用完,给出正确答案
* 3,总分输出。
*/
public class DisplayResult {


    public static void showError(int times) {
            System.out.println("You have given a wrong answer," +
                    "please try again(You have )" + times + " times left:";
    }

    public static void showRightAnswer(int result) {
        System.out.println("The right answer is : " + result);
    }

    public static void showTotalScore(int total) {
        if (total > 90) {
            System.out.println("SMART!";
        } else if (total > 80 && total < 90) {
            System.out.println("GOOD!";
        } else if (total < 80 && total > 70) {
            System.out.println("OK";
        } else if (total < 70 && total > 60){
            System.out.println("PASS";
        } else {
            System.out.println("TRY AGAIN";
        }
    }

    public static void showInput() {
        System.out.println("Please input the answer: ";
    }

    public static void showEquation(String equation) {
        System.out.println(equation);
    }
}
能帮我解决小学生测验编程不?-1
Image1.png


能帮我解决小学生测验编程不?-2
Image2.png


能帮我解决小学生测验编程不?-3
Image3.png

» 本帖已获得的红花(最新10朵)

9楼2017-05-19 14:57:27
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

amefd

专家顾问

优秀!!有木有!!!优秀!!有木有!!!优秀!!有木有!!!优秀!!有木有!!!


小木虫: 金币+0.5, 给个红包,谢谢回帖
我还以为现在小学生测验题就要考编程呢

发自小木虫Android客户端
PhD是人类的好朋友。
8楼2017-05-19 14:06:36
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

wangybcn

专家顾问


小木虫: 金币+0.5, 给个红包,谢谢回帖
本帖内容被屏蔽

15楼2017-05-21 18:41:34
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

TX灌水员

实习版主

优秀!!有木有!!!优秀!!有木有!!!优秀!!有木有!!!优秀!!有木有!!!


小木虫: 金币+0.5, 给个红包,谢谢回帖
送红花一朵
引用回帖:
9楼: Originally posted by lbstorm at 2017-05-19 14:57:27
//一共三个java类。写得不好,不足的地方欢迎指正。
// 1.
package com.test.muchong.pupil;

import java.util.Scanner;

/**
* Created by Lieber on 2017/5/19.
*/
public class Check {
    public ...

2333
人家要交C语言的作业啊
11楼2017-05-19 16:07:13
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
普通回帖

smitest

兑换贵宾

优秀!!有木有!!!优秀!!有木有!!!优秀!!有木有!!!优秀!!有木有!!!

2楼2017-05-18 23:34:31
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

ioadong

实习版主

优秀!!有木有!!!优秀!!有木有!!!优秀!!有木有!!!优秀!!有木有!!!


小木虫: 金币+0.5, 给个红包,谢谢回帖
你应该到CSDN之类的专业讨论程序设计的论坛。
以科学的理性代替天然的非理性。
3楼2017-05-19 08:37:54
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

黄靖淞

专家顾问

优秀!!有木有!!!优秀!!有木有!!!优秀!!有木有!!!优秀!!有木有!!!


小木虫: 金币+0.5, 给个红包,谢谢回帖
等我有空了,我会用stm32来练练手的

发自小木虫Android客户端
5楼2017-05-19 08:55:20
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

凡尘清泉

兑换贵宾

优秀!!有木有!!!优秀!!有木有!!!优秀!!有木有!!!优秀!!有木有!!!

谢谢,不能
我给大家讲个笑话啊,等我博士毕业之后……
6楼2017-05-19 11:55:47
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

zyqh

专家顾问

优秀!!有木有!!!优秀!!有木有!!!优秀!!有木有!!!优秀!!有木有!!!


小木虫: 金币+0.5, 给个红包,谢谢回帖
引用回帖:
4楼: Originally posted by ioadong at 2017-05-19 08:54:09
忍不住,还是要说下,现实中没有人喜欢你这种一点点自己的想法都没有,直接伸手要答案的。
你真心想找人帮忙也应该自己拿出点可以讨论的东西出来。空手而来只会空手而去。

别人是妹子,专门为这个问题而注册账号的。哈哈
雨后方能见彩虹
7楼2017-05-19 12:17:40
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

lbstorm

管理员

优秀!!有木有!!!优秀!!有木有!!!优秀!!有木有!!!优秀!!有木有!!!


小木虫: 金币+0.5, 给个红包,谢谢回帖
引用回帖:
9楼: Originally posted by lbstorm at 2017-05-19 14:57:27
//一共三个java类。写得不好,不足的地方欢迎指正。
// 1.
package com.test.muchong.pupil;

import java.util.Scanner;

/**
* Created by Lieber on 2017/5/19.
*/
public class Check {
    public ...

这回复功能里自动添加的表情也是让人醉了
10楼2017-05-19 15:00:24
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 茶家美 Aimee 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 材料调剂 +10 Eujd1 2026-03-31 11/550 2026-04-01 11:23 by ivanqyq
[考研] 086000生物与医药298调剂求助 +4 元元青青 2026-03-31 6/300 2026-04-01 11:13 by syh9288
[考研] 296求调剂 +3 汪!?! 2026-03-31 5/250 2026-04-01 11:10 by 逆水乘风
[考研] 土木304求调剂 +5 顶级擦擦 2026-03-31 5/250 2026-04-01 08:15 by fdcxdystjk¥
[考研] 各位老师好,我的一志愿为北京科技大学085601材料专硕 +12 Koxui 2026-03-28 12/600 2026-03-31 23:17 by wwytracy
[考研] 070300化学354求调剂 +15 101次希望 2026-03-28 15/750 2026-03-31 17:58 by jp9609
[考研] 材料求调剂 一志愿哈工大总分298分,前三科223分 +11 dongfang59 2026-03-27 11/550 2026-03-31 16:51 by Wang200018
[考研] 考研调剂求助 +7 13287130938 2026-03-31 7/350 2026-03-31 16:39 by 690616278
[考研] 材料工程专硕求调剂 +10 hyl3153942 2026-03-29 10/500 2026-03-31 16:31 by hypershenger
[考研] 353求调剂 +3 江上枫_26 2026-03-28 3/150 2026-03-31 15:53 by jp9609
[考研] 调剂求院校招收 +7 鹤鲸鸽 2026-03-28 7/350 2026-03-31 11:21 by oooqiao
[考研] 08工科,295,接受跨专业调剂 +6 lmnlzy 2026-03-30 6/300 2026-03-31 10:04 by cal0306
[考研] 抱歉 +3 田洪有 2026-03-30 3/150 2026-03-30 19:11 by 迷糊CCPs
[考研] 343求调剂085601 +3 要努力学习x 2026-03-29 3/150 2026-03-29 18:35 by wxiongid
[考研] 材料与化工(0856)304求B区调剂 +8 邱gl 2026-03-27 8/400 2026-03-28 12:42 by 唐沐儿
[考研] 331环境科学与工程求调剂 +3 熠然好运气 2026-03-27 3/150 2026-03-28 04:11 by fmesaito
[考研] 一志愿211院校 344分 东北农业大学生物学学硕,求调剂 +5 丶风雪夜归人丶 2026-03-26 8/400 2026-03-27 19:22 by 丶风雪夜归人丶
[考研] 266分求材料化工冶金矿业等专业的调剂 +4 哇呼哼呼哼 2026-03-26 4/200 2026-03-27 17:02 by zhyzzh
[考研] 321求调剂 +6 wasdssaa 2026-03-26 6/300 2026-03-26 20:57 by sanrepian
[考研] 机械学硕310分,数一英一,一志愿211本科双非找调剂信息 +3 @357 2026-03-25 3/150 2026-03-26 16:34 by by.MENG
信息提示
请填处理意见