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

Develop a GUI java application to conduct a cultural contest between two players

ID: 3580176 • Letter: D

Question

Develop a GUI java application to conduct a cultural contest between two players. Your application will consist of the following parts: Part 1: develop a class to represent a question and its answer. Each question will consist of a question text, three options (one of them is the answer) and the answer. You should provide constructor(s), toString, equals and any other appropriate methods. Part 2: develop a JFrame to allow an administrator to enter questions and save them to a file. The frame should look like Figure 1. When the administrator clicks on the save button, a question object should be appended to the question file (questions.dat). The reset button clears all fields of the frame and the exit button exits the frame after closing all streams. Part 3: develop the contest JFrame class that will allow two players to compete. Your class should first open the questions file (created in Part 2) and read all the question objects from it into an ArrayList object. Appropriate error message should be displayed if the file could not be opened. Players should alternatively be asked random questions from the ArrayList object. Questions that are asked should not be repeated again. There is a single point for each correct answer and the score for each player should be updated accordingly. When no more questions were available, the program should display appropriate message and then terminate. See Figure 2 for a sample run. Please note the following: · The assignment will be graded based on the design and correct execution of the application. You must submit the whole project along with your questions file (i.e. compress everything and upload it to Moodle). Bonus marks will be given for extra functionality (based on instructor judgment).

Explanation / Answer

import java.awt.*; import java.awt.font.FontRenderContext; import java.awt.geom.Rectangle2D; import javax.swing.JFrame; import javax.swing.JPanel; public class Main extends JPanel { public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setFont(new Font("Serif", Font.PLAIN, 48)); paintHorizontallyCenteredText(g2, "Java Source", 200, 75); paintHorizontallyCenteredText(g2, "and", 200, 125); paintHorizontallyCenteredText(g2, "Support", 200, 175); } protected void paintHorizontallyCenteredText(Graphics2D g2, String s, float centerX, float baselineY) { FontRenderContext frc = g2.getFontRenderContext(); Rectangle2D bounds = g2.getFont().getStringBounds(s, frc); float width = (float) bounds.getWidth(); g2.drawString(s, centerX - width / 2, baselineY); } public static void main(String[] args) { JFrame f = new JFrame(); f.getContentPane().add(new Main()); f.setSize(450, 350); f.setVisible(true); } }