Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

GUI Practice Java Trivia Game Write a GUI program that lets the user play a simp

ID: 3680027 • Letter: G

Question

GUI Practice Java

Trivia Game Write a GUI program that lets the user play a simple trivia game. Use a layout of your choice with the appropriate text fields, labels, and buttons to implement your design. The game should ask only one question at a time and output the correct answer to a GUI component (e.g. label, textfield, etc.) if the player answers a question incorrectly. When all questions have been answered, show the final score and exit the program. The game should have five questions. Each question should have a corresponding answer and point value between 1 and 3 based on the difficulty of the question. Implement the game using a single array of a Trivia object which encapsulates a question, answer, and point value for a particular trivia item. You can pick the trivia questions, answers, and point values.

Serialization You probably hard-coded the trivia questions, answers, and point values for the previous problem. For this problem, write an administrative interface so someone can add or delete questions/answers/values. It is your option if you want to be able to edit existing questions. Your administrative program should save and load data using serialization with binary output and input. Modify your program from question 2 so that it loads the data file saved via serialization. Your interface doesn't need to be GUI-based, it can be all text, but if you make a GUIbased solution you can earn up to 10 additional extra credit points!

Explanation / Answer

import java.io.File; import java.io.IOException; import java.util.Scanner; public class TriviaGame { public static void main(String args[]) throws IOException { // Constants final int NUM_QUESTIONS = 10; final int NUM_PLAYERS = 2; // Variables int playerTurn = 1; // The current player int questionNum; // The current question number int playerAnswer; // The player's chosen answer int player1points = 0; // Player 1's points int player2points = 0; // Player 2's points // Create an array of Player objects for player #1 and player #2. Player[] players = new Player[NUM_PLAYERS]; for (int i = 0; i