我想随机提出一些问题,但总是提出一个新问题

时间:2019-05-04 13:06:43

标签: java android xml

我想创建一个带有问题的游戏,问题是随机的,但是有很多重复的问题。我希望这个问题只能出现一次。我的游戏有所有活动的代码

public class Activity extends AppCompatActivity {

    private TextView mQuestionTextViewVe;
    private QuestionBankVe mQuestionBankVe;
    private QuestionVeriter mCurrentQuestionVe;
    private Button mbackButton;
    private ArrayList<String> arrayList;


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

        System.out.println("veriterActivity::onCreate()");

        mQuestionBankVe = this.generateQuestions();

        mQuestionTextViewVe = findViewById(R.id.activity_veriter_question_text);

        mCurrentQuestionVe = mQuestionBankVe.getQuestion();
        this.displayQuestion(mCurrentQuestionVe);

    private void displayQuestion(final QuestionVeriter question) {
        mQuestionTextViewVe.setText(question.getQuestion());
    }

    private QuestionBankVe generateQuestions() {
        QuestionVeriter question1 = new QuestionVeriter("Question");
        QuestionVeriter question2 = new QuestionVeriter("Question");
        QuestionVeriter question3 = new QuestionVeriter("Question");

        return new QuestionBankVe(Arrays.asList( question1,
        question2
        question3

        ));
    }
}
public class QuestionBankVe {

        private List<QuestionVeriter> mQuestionListVe;
        private int mNextQuestionIndexVe;

        public QuestionBankVe(List<QuestionVeriter> questionListVe) {
            mQuestionListVe = questionListVe;

            // Shuffle the question list
            Collections.shuffle(mQuestionListVe);

            mNextQuestionIndexVe = 0;
        }

        public QuestionVeriter getQuestion() {
            // Ensure we loop over the questions
            if (mNextQuestionIndexVe == mQuestionListVe.size()) {
                mNextQuestionIndexVe = 0;
            }

            // Please note the post-incrementation
            return mQuestionListVe.get(mNextQuestionIndexVe++);
        }
    }
public class QuestionVeriter {

    private String mQuestionVe;



    public QuestionVeriter(String question) {
        this.setQuestion(question);
    }


    public String getQuestion() {
        return mQuestionVe;
    }

    public void setQuestion(String question) {
        mQuestionVe = question;
    }


    @Override
    public String toString() {
        return "Question{" +
                "mQuestion='" + mQuestionVe + '\'' +
                '}';
    }
}

0 个答案:

没有答案