228k views
2 votes
Trivia Game In this programming challenge, you will create a simple trivia game for two players. The program will work like this: Starting with player 1, each player gets a turn at answering 5 trivia questions. (There are 10 questions, 5 for each player.) When a question is displayed, four possible answers are also displayed. Only one of the answers is correct, and if the player selects the correct answer, he or she earns a point. After answers have been selected for all of the questions, the program displays the number of points earned by each player and declares the player with the highest number of points the winner. You are to design a Question class to hold the data for a trivia question. The Question class should have String fields for the following data: A trivia question Possible answer 1 Possible answer 2 Possible answer 3 Possible answer 4 The number of the correct answer (1, 2, 3, or 4) The The Question class should have appropriate constructor(s), accessor, and mutator methods.

User Katherina
by
7.4k points

1 Answer

1 vote

Answer:

See explaination

Step-by-step explanation:

public class Question {

private String question;

// Answer

private String firstAnswer;

private String secondAnswer;

private String thirdAnswer;

private String fourthAnswer;

// Correct answer

private String correctAnswer;

/**

*

* atparam question

* atparam firstAnswer

* atparam secondAnswer

* atparam thirdAnswer

* atparam fourthAnswer

* atparam correctAnswer

*/

public Question(String question, String firstAnswer, String secondAnswer, String thirdAnswer, String fourthAnswer,

String correctAnswer) {

super();

this.question = question;

this.firstAnswer = firstAnswer;

this.secondAnswer = secondAnswer;

this.thirdAnswer = thirdAnswer;

this.fourthAnswer = fourthAnswer;

this.correctAnswer = correctAnswer;

}

// getter and setter

public String getQuestion() {

return question;

}

public void setQuestion(String question) {

this.question = question;

}

public String getFirstAnswer() {

return firstAnswer;

}

public void setFirstAnswer(String firstAnswer) {

this.firstAnswer = firstAnswer;

}

public String getSecondAnswer() {

return secondAnswer;

}

public void setSecondAnswer(String secondAnswer) {

this.secondAnswer = secondAnswer;

}

public String getThirdAnswer() {

return thirdAnswer;

}

public void setThirdAnswer(String thirdAnswer) {

this.thirdAnswer = thirdAnswer;

}

public String getFourthAnswer() {

return fourthAnswer;

}

public void setFourthAnswer(String fourthAnswer) {

this.fourthAnswer = fourthAnswer;

}

public String getCorrectAnswer() {

return correctAnswer;

}

public void setCorrectAnswer(String correctAnswer) {

this.correctAnswer = correctAnswer;

}

// toString method for print the question

atOverride

public String toString() {

return question + "\\" + firstAnswer + "\\" + secondAnswer + "\\" + thirdAnswer + "\\" + fourthAnswer;

}

}

Note: The at in the lines of the program should be converted to at symbol.

/******************************qustions.txt*****************************/

Which is a reserved word in the Java programming language?

A. method

B. native

C. subclasses

D. reference

B

Which is a valid keyword in java?

A. interface

B. string

C. Float

D. unsigned

A

Which is the valid declarations within an interface definition?

A. public double methoda();

B. public final double methoda();

C. static void methoda(double d1);

D. protected void methoda(double d1);

A

Which is a valid declarations of a String?

A. String s1 = null;

B. String s2 = 'null';

C. String s3 = (String) 'abc';

D. String s4 = (String) '\ufeed';

A

User Cpurdy
by
7.8k points