In java write a program of the following: Write a program that plays a simple tr
ID: 3639433 • Letter: I
Question
In java write a program of the following:Write a program that plays a simple trivia game. The game should have five questions. Each question has a corresponding answer and point value between 1 and 3 based on the difficulty of the question. implement the game using three arrays. An array of type String should be used for the questions. Another array of type String should be used to store the answers. An array of type int should be declared of size 5.
The index into the three arrays can be used to tie the question, answer, and point value together. For example, the item at index 0 for each array would correspond to question 1, answer 1, and the point value for question 1. The item at index 1 for each array would correspond to question 2, answer 2, and the point value for question 2, and so forth. Manually hardcode the five questions, answers, and point values into your program using trivia of your choice.
Your program should ask the player each question one at a time and allow the player to enter an answer. If the player's answer matches the actual answer, the player wins the number of points for that question. If the player's answer is incorrect, the player wins no points for that question. Your program should allow the correct answer if the player is incorrect. After the player has answered all five questions, the game is over, and your program should display the player's total score.
Please be detailed on how you wrote this program
Explanation / Answer
import java.awt.BorderLayout; import java.awt.Color; import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.IOException; import java.util.Scanner; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class TriviaGame { public static void main(String[] args, Question[] qArray) throws IOException { // Constants final int NUM_QUESTIONS = 5; final int NUM_PLAYERS = 1; // Variables int playerTurn = 1; // The current player int questionNum; // The current question number int playerAnswer; // The player's chosen answer int player1points = 0; // Player's points // Create an array of Player objects for player #1 and player #2. Player[] players = new Player[NUM_PLAYERS]; for (int i = 0; iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.