/**
* 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);
}
/**
* 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);
}
}
Image1.png
//一共三个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);
}
}
Image1.png
Image2.png
Image3.png
,
这回复功能里自动添加的表情也是让人醉了
2333
人家要交C语言的作业啊
看图上的要求,人家要的是C语言的。
c语言很简单的。
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int i,count,n,n1,n2,op,in,re,tmp;
count=10;
re=0;
for(i=0;i<count;i++)
{
printf("\n-----------\n计算第 %d 题 ",i+1);
n=0;
srand(i+(unsigned)time(NULL));
op=rand()%4;
if(op<2)//加法
{
n1=rand()%50;
n2=rand()%(50-n1);
printf("计算加法,输入后按回车 %d+%d=",n1,n2);
for(n=0;n<3;n++){
scanf("%d",&in);
if(in==(n1+n2))
{
printf("输入正确\n"
if(n==0)
re=re+10;
if(n==1)
re=re+7;
if(n==2)
re=re+5;
break;
}
else
{
printf("\n第%d次输入不正确,重新输入:%d+%d=",n+1,n1,n2);
}
}
}
else//减法
{
n1=rand()%50;
n2=rand()%50;
if(n1<n2)
{
tmp=n1;
n1=n2;
n2=tmp;
}
printf("计算减法,输入后按回车 %d-%d=",n1,n2);
for(n=0;n<3;n++){
scanf("%d",&in);
if(in==(n1-n2))
{
printf("输入正确\n"
if(n==0)
re=re+10;
if(n==1)
re=re+7;
if(n==2)
re=re+5;
break;
}
else
{
printf("\n第%d次输入不正确,重新输入:%d-%d=",n+1,n1,n2);
}
}
}
printf("\n当前总分数:%d\n",re);
}
printf("\n===============\n最后得分:%d\n",re);
}
这程序,我也送个花