gpt4 book ai didi

java - 多类别测验应用程序

转载 作者:行者123 更新时间:2023-12-02 12:14:25 24 4
gpt4 key购买 nike

我正在制作一个测验应用程序,其中包含有关不同国家/地区的问题。我已经让它适用于一个国家/地区,但现在我想让它适用于所有国家/地区,但我不知 Prop 体如何操作。我已经制作了一个题库和一个测验 Activity ,但我现在不知道如何进行,所以我希望有人可以帮助我。

这是我的测验 Activity :

package com.example.quizapp;


import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class QuizActivity extends AppCompatActivity {

private QuestionLibrary mQuestionLibrary = new QuestionLibrary();

private TextView mScoreView;
private TextView mQuestionView;
private Button mButtonChoice1;
private Button mButtonChoice2;
private Button mButtonChoice3;
private Button mButtonChoice4;

private String mAnswerFrankrijk;
private int mScoreFrankrijk = 0;
private int mQuestionNumber = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quiz);

mScoreView = (TextView)findViewById(R.id.score1);
mQuestionView = (TextView)findViewById(R.id.question1);
mButtonChoice1 = (Button)findViewById(R.id.choice1);
mButtonChoice2 = (Button)findViewById(R.id.choice2);
mButtonChoice3 = (Button)findViewById(R.id.choice3);
mButtonChoice4 = (Button)findViewById(R.id.choice4);

updateQuestion();

//Start of Button Listener for Button1
mButtonChoice1.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
//My logic for Button goes in here

if (mButtonChoice1.getText() == mAnswerFrankrijk){
mScoreFrankrijk = mScoreFrankrijk + 1;
updateScore(mScoreFrankrijk);
updateQuestion();
//This line of code is optiona
Toast.makeText(QuizActivity.this, "Goed", Toast.LENGTH_SHORT).show();

}else {
Toast.makeText(QuizActivity.this, "Fout", Toast.LENGTH_SHORT).show();
updateQuestion();
}
}
});

//End of Button Listener for Button1

//Start of Button Listener for Button2
mButtonChoice2.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
//My logic for Button goes in here

if (mButtonChoice2.getText() == mAnswerFrankrijk){
mScoreFrankrijk = mScoreFrankrijk + 1;
updateScore(mScoreFrankrijk);
updateQuestion();
//This line of code is optiona
Toast.makeText(QuizActivity.this, "Goed", Toast.LENGTH_SHORT).show();

}else {
Toast.makeText(QuizActivity.this, "Fout", Toast.LENGTH_SHORT).show();
updateQuestion();
}
}
});

//End of Button Listener for Button2


//Start of Button Listener for Button3
mButtonChoice3.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
//My logic for Button goes in here

if (mButtonChoice3.getText() == mAnswerFrankrijk){
mScoreFrankrijk = mScoreFrankrijk + 1;
updateScore(mScoreFrankrijk);
updateQuestion();
//This line of code is optiona
Toast.makeText(QuizActivity.this, "Goed", Toast.LENGTH_SHORT).show();

}else {
Toast.makeText(QuizActivity.this, "Fout", Toast.LENGTH_SHORT).show();
updateQuestion();
}
}
});

//End of Button Listener for Button3

//Start of Button Listener for Button3
mButtonChoice4.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
//My logic for Button goes in here

if (mButtonChoice4.getText() == mAnswerFrankrijk){
mScoreFrankrijk = mScoreFrankrijk + 1;
updateScore(mScoreFrankrijk);
updateQuestion();
//This line of code is optional
Toast.makeText(QuizActivity.this, "Goed", Toast.LENGTH_SHORT).show();

}else {
Toast.makeText(QuizActivity.this, "Fout", Toast.LENGTH_SHORT).show();
updateQuestion();
}
}
});

//End of Button Listener for Button3




}

private void updateQuestion(){
mQuestionView.setText(mQuestionLibrary.getQuestionFrankrijk(mQuestionNumber));
mButtonChoice1.setText(mQuestionLibrary.getChoice1Frankrijk(mQuestionNumber));
mButtonChoice2.setText(mQuestionLibrary.getChoice2Frankrijk(mQuestionNumber));
mButtonChoice3.setText(mQuestionLibrary.getChoice3Frankrijk(mQuestionNumber));
mButtonChoice4.setText(mQuestionLibrary.getChoice4Frankrijk(mQuestionNumber));

mAnswerFrankrijk = mQuestionLibrary.getCorrectAnswerFrankrijk(mQuestionNumber);
mQuestionNumber++;
}


private void updateScore(int point) {mScoreView.setText("" + mScoreFrankrijk);
}



}

这是我的问题库:

package com.example.quizapp;

public class QuestionLibrary {

private String mQuestionsFrankrijk [] = {
"Wat is de hoofdstad van Frankrijk?",
"Wat is de bijnaam van het Franse nationale voetbalelftal",
"Welke van de volgende landen grenst niet aan Frankrijk?",
"Bij welke sport hoort 'le maillot jaune'?",
"Welk museum in Parijs heeft een piramide als ingang?"
};

private String mChoicesFrankrijk [][] = {
{"Lyon", "Parijs", "Nice", "Bordeaux"},
{"La France", "Le Coq Sportif", "Les Bleus", "Les Gagnants"},
{"Zwitserland", "België", "Spanje", "Oostenrijk"},
{"Tennis", "Wielrennen", "Rugby", "Cricket"},
{"Musée d'Orsay", "Musée Rodin", "Louvre", "Centre Georges Pompidou"},

};

private String mCorrectAnswers [] = {"Parijs", "Les Bleus", "Oostenrijk", "Wielrennen", "Louvre"};



public String getQuestionFrankrijk(int a) {
String question = mQuestionsFrankrijk[a];
return question;
}

public String getChoice1Frankrijk(int a) {
String choice0 = mChoicesFrankrijk[a][0];
return choice0;
}

public String getChoice2Frankrijk(int a) {
String choice1 = mChoicesFrankrijk[a][1];
return choice1;
}
public String getChoice3Frankrijk(int a) {
String choice2 = mChoicesFrankrijk[a][2];
return choice2;
}
public String getChoice4Frankrijk(int a) {
String choice3 = mChoicesFrankrijk[a][3];
return choice3;
}

public String getCorrectAnswerFrankrijk(int a) {
String answer = mCorrectAnswers[a];
return answer;
}
}

最佳答案

我能想到的最简单的解决方案是使 QuestionLibrary 成为一个接口(interface)或抽象类。然后实现包含特定国家/地区问题的 Country1QuestionLibrary 和包含另一组问题的 Country2QuestionLibrary。然后,您可以通过执行

动态交换向用户呈现的问题集

questionLibrary = new Country1QuestionLibrary();

那么您需要一种方法让您的用户更改国家/地区。在 UI 上,添加另一个“更改国家/地区”按钮,其实现方式与其他按钮的工作方式类似。在 onClickListener 中,将 QuestionLibrary 的其他实现分配给可用问题并刷新问题和答案 View 。

与大多数编程一样,有很多方法可以实现这一点。如果您可以实现我所展示的路径,请在看到该解决方案的缺点或限制后,花一些时间尝试自己提出不同的解决方案。

关于java - 多类别测验应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46302764/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com