Answer:
Step-by-step explanation:
The following code is written in Java, It creates the class for the Trivia game along with the arrays, variables, and methods as requested so that it works flawlessly with the provided main method/test driver. The attached picture shows the output of the code.
import java.util.Arrays;
import java.util.Scanner;
class TriviaGameV1 {
String[] questions = {"The first Pokemon that Ash receives from Professor Oak is?", "Erling Kagge skiied into here alone on January 7, 1993", "1997 British band that produced 'Tub Thumper'", "Who is the tallest person on record (8 ft. 11 in) that has lived?", "PT Barnum said \"This way to the _______\" to attract people to the exit."};
String[] answers = {"pikachu", "south pole", "chumbawumba", "robert wadlow", "egress"};
int[] points = { 1, 2, 2, 3, 1};
int score;
int count = 0;
public void TriviaGameV1() {
this.score = 0;
}
public boolean askNextQuestion() {
if (count != 5) {
Scanner in = new Scanner(System.in);
System.out.println(questions[count]);
String answer = in.nextLine().toLowerCase();
if (answer.equals(answers[count])) {
score += points[count];
} else {
System.out.println("Wrong, the correct answer is : " + answers[count]);
}
count += 1;
return true;
}
return false;
}
public void showScore() {
System.out.println("Your Score is: " + this.score);
}
public static void main(String[] args) {
TriviaGameV1 game = new TriviaGameV1();
while (game.askNextQuestion()) {
game.showScore();
}
System.out.println("Game over! Thanks for playing!");
}
}