Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Question {
- private int questionNumber; //representing the question #
- private String theQuestion; //the question itself.
- private String[] answers; //all the answers of the question
- private String correctAnswer; //string of the correct answer
- //contructor
- public Question (int questionNumber, String question, String[] answersInput, String correctAnswerInput) {
- this.questionNumber = questionNumber;
- this.theQuestion = question;
- this.answers = new String[answersInput.length];
- for (int i = 0; i < this.answers.length; i++) {
- this.answers[i] = answersInput[i];
- }
- //setting the correct answer
- this.correctAnswer = correctAnswerInput;
- }
- //getter for correctAnswer
- public String getCorrectAnswer() {
- return this.correctAnswer;
- }
- //getter for answer the user selected
- public String getAnswer(int answerLabel) {
- return this.answers[answerLabel - 1];
- }
- //toString to print the question and all of the possible answers.
- public String toString() {
- String questionString = "";
- questionString += "Question #" + this.questionNumber + ":\t" + this.theQuestion + "\n\n";
- //presents all of the answers in the list.
- for (int i = 0; i < this.answers.length; i++) {
- questionString += (i + 1) + ": " + this.answers[i] + "\n";
- }
- return questionString;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement