重复随机数题
Repeated random number questions
我有以下 class 需要向用户显示随机问题。
但是我的问题是 class 只显示一个问题,而不是连续提问。
我怎样才能重复用户的问题以保持他们的!分数?
见下图 -
public class Chooser extends ActionBarActivity implements View.OnClickListener {
int randomOne = 0;
int randomTwo = 0;
int problems = 0;
int sum = 0;
int userAnswer = 0;
int correct = 0;
int inCorrect = 0;
int userInput, result;
TextView question, response, answer, report;
EditText userNumber;
Button ans;
private Random add;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chooser);
question = (TextView) findViewById(R.id.question);
response = (TextView) findViewById(R.id.response);
answer = (TextView) findViewById(R.id.answers);
report = (TextView) findViewById(R.id.report);
userNumber = (EditText) findViewById(R.id.answer);
ans = (Button) findViewById(R.id.button);
ans.setOnClickListener(this);
add = new Random();
randomOne = add.nextInt(20);
randomTwo = add.nextInt(10);
Display();
}
public void Display() {
sum = randomOne + randomTwo;
question.setText(randomOne + " + " + randomTwo);
}
@Override
public void onClick(View v) {
userInput = Integer.parseInt(userNumber.getText().toString());
Log.e("getting user input", "" + userInput);
if (userInput == sum) {
response.append(" CORRECT! , You are the best \n");
correct++;
} else {
response.append("INCORRECT, The correct answer was :" + sum + "\n");
inCorrect++;
}
problems++;
}
}
我不确定我是否理解你的问题,但假设你希望在用户每次单击 "submit" 按钮时向用户显示一个不同的 "problem",你应该调用 "Display()" 方法单击按钮后,还通过每次将 randomOne &randomTwo 设置为 nextInt(some_number) 来生成新的随机数...希望这对您有所帮助..
我有以下 class 需要向用户显示随机问题。
但是我的问题是 class 只显示一个问题,而不是连续提问。
我怎样才能重复用户的问题以保持他们的!分数?
见下图 -
public class Chooser extends ActionBarActivity implements View.OnClickListener {
int randomOne = 0;
int randomTwo = 0;
int problems = 0;
int sum = 0;
int userAnswer = 0;
int correct = 0;
int inCorrect = 0;
int userInput, result;
TextView question, response, answer, report;
EditText userNumber;
Button ans;
private Random add;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chooser);
question = (TextView) findViewById(R.id.question);
response = (TextView) findViewById(R.id.response);
answer = (TextView) findViewById(R.id.answers);
report = (TextView) findViewById(R.id.report);
userNumber = (EditText) findViewById(R.id.answer);
ans = (Button) findViewById(R.id.button);
ans.setOnClickListener(this);
add = new Random();
randomOne = add.nextInt(20);
randomTwo = add.nextInt(10);
Display();
}
public void Display() {
sum = randomOne + randomTwo;
question.setText(randomOne + " + " + randomTwo);
}
@Override
public void onClick(View v) {
userInput = Integer.parseInt(userNumber.getText().toString());
Log.e("getting user input", "" + userInput);
if (userInput == sum) {
response.append(" CORRECT! , You are the best \n");
correct++;
} else {
response.append("INCORRECT, The correct answer was :" + sum + "\n");
inCorrect++;
}
problems++;
}
}
我不确定我是否理解你的问题,但假设你希望在用户每次单击 "submit" 按钮时向用户显示一个不同的 "problem",你应该调用 "Display()" 方法单击按钮后,还通过每次将 randomOne &randomTwo 设置为 nextInt(some_number) 来生成新的随机数...希望这对您有所帮助..