它是这样的:Project4Appclass的目的是为儿童创建一个数学游戏,以加强他们的加法和减法技能。为了让游戏允许学生获得足够的练习,游戏将向学生提出10个问题。如果学生得到正确的前10个问题,游戏应该结束。否则,游戏应继续进行,直到发生以下两种情况之一:1)学生正确答案的百分比至少达到85%,或2)学生已完成20个问题。当游戏结束时,应该告诉学生他/她正确和不正确的添加问题的数量以及他/她得到的正确和不正确的减法问题的数量。它还应给出一个分数,即他/她得到的问题的百分比。 (并且不使用“休息”)
package proj3;
import java.util.Random;
public class Question {
private int operand1;
private int operand2;
private char operator;
/**
* <p> Name: main method </p>
*
*/
public Question()
{
Random rand = new Random();
boolean random = rand.nextBoolean();
if(rand.nextBoolean())
{
operator = '+';
operand1 = rand.nextInt(13);
operand2 = rand.nextInt(13);
}
else
{
operator = '-';
operand1 = rand.nextInt(13 - 6) + 6;
operand2 = rand.nextInt((operand1 - 0) + 1) + 0;
}
}
/**
* getOperand1 method - returns what's stored in the instance variable value
* @return the state of the instance variable value
*/
public int getOperand1()
{
return operand1;
}
/**
* getOperand2 method - returns what's stored in the instance variable value
* @return the state of the instance variable value
*/
public int getOperand2()
{
return operand2;
}
/**
* getOperator method - returns what's stored in the instance variable value
* @return the state of the instance variable value
*/
public char getOperator()
{
return operator;
}
/**
* toString method - this method returns the state of the Question object
* @return a reference to a String object that contains
* the operands and the operator
*/
public String toString()
{
String question;
question = operand1 + " " + operator + " " + operand2 + " " + "=";
return question;
}
/**
* determineAnswer method - this method returns the state of the card object
* @return a reference to a Question object that contains the answer to
* a random question.
*/
public int determineAnswer()
{
if(operator == '+')
return operand1 + operand2;
else
return operand1 - operand2;
}
}
这就是Project4App目前的样子(坚持)
public static void main(String [] args)
{
Scanner scan = new Scanner(System.in);
int percentage = 0;
int questions = 0;
while( questions > 10 && questions < 20 && percentage >= 85.0)
{
Question q = new Question();
System.out.println("What is the result?");
System.out.println(q);
int answer = scan.nextInt();
if(answer == q.determineAnswer())
System.out.println("Congratulations, you got it correct!");
else
System.out.println("The correct answer for " + q + " is " + q.determineAnswer());
}
/**for(int i =0; i <= 20; i++)
{
Question q = new Question();
System.out.println("What is the result?");
System.out.println(q);
int answer = scan.nextInt();
if(answer == q.determineAnswer())
{
System.out.println("Congratulations, you got it correct!");
}
else
System.out.println("The correct answer for " + q + " is " + q.determineAnswer());
}
**/
}
}
如何继续,我们将不胜感激。
答案 0 :(得分:0)
我没有测试
boolean isOver = false;
while( !isOver ){
questions++;
Question q = new Question();
System.out.println("What is the result?");
System.out.println(q);
int answer = scan.nextInt();
if(answer == q.determineAnswer())
System.out.println("Congratulations, you got it correct!");
else
System.out.println("The correct answer for " + q + " is "+ q.determineAnswer());
if( (questions > 10 && percentage >= 85.0) || questions == 20){
isOver = true;
}
}