Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following question is based on Java Programming Language. The code will be provided below can you find and fix the error that is in

The following question is based on Java Programming Language. The code will be provided below can you find and fix the error that is in the code ? The code is about a quiz system Students need to attend 5 question and after they did the quiz they can view their score.

package childrenlanguagelearningsystem; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ButtonGroup; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JRadioButton; public class QuizEng extends javax.swing.JFrame { String[] questions = {"The students are __ their notes ?","The doctor _ out for ten minutes ?","The new restaurant _ last week ?","It is __ ?","The train _ on time ?"}; String[][]options = {{"Wrote","Written","Writing","Write","Writes"},{"Goes","Going","Gone","Went","Go"},{"Open","Opens"," Opening","Opened","Starts"},{"Wndrful","Wonderfool","Wunderful","Wonderful","Wonderfull"},{"Arrivid","Arived","Arrives","Arrived","Arrrived"}}; int index = 0, correct = 0; ButtonGroup bg = new ButtonGroup(); public QuizEng() { initComponents(); bg.add(jRadioButton1_); bg.add(jRadioButton2_); bg.add(jRadioButton3_); bg.add(jRadioButton4_); jButton_Next_Q.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { jButton_Next_QActionPerformed(null); } }); jRadioButton1_.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { getSelectedOption(jRadioButton1_); } }); jRadioButton2_.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { getSelectedOption(jRadioButton2_); } }); jRadioButton3_.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { getSelectedOption(jRadioButton3_); } }); jRadioButton4_.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { getSelectedOption(jRadioButton4_); } }); jButton_Next_QActionPerformed(null); } public void getSelectedOption(JRadioButton rbtn) { System.out.println(rbtn.getText()); System.out.println(options[index][4]); if (rbtn.getText().equals(options[index][4])) { correct++; } index++; if (index == questions.length) { JOptionPane.showMessageDialog(this, "Quiz complete! Your score is " + correct + " out of " + questions.length); System.exit(0); } } public void enableRbuttons(boolean yes_or_no) { jRadioButton1_.setEnabled(yes_or_no); jRadioButton2_.setEnabled(yes_or_no); jRadioButton3_.setEnabled(yes_or_no); jRadioButton4_.setEnabled(yes_or_no); } @SuppressWarnings("unchecked") //  private void initComponents() { jRadioButton1_ = new javax.swing.JRadioButton(); jRadioButton2_ = new javax.swing.JRadioButton(); jRadioButton3_ = new javax.swing.JRadioButton(); jRadioButton4_ = new javax.swing.JRadioButton(); jButton_Next_Q = new javax.swing.JButton(); jPanel_Q_Container = new javax.swing.JPanel(); Lbl_Question = new javax.swing.JLabel(); jLabel1 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); getContentPane().setLayout(null); jRadioButton1_.setText("jRadioButton1"); jRadioButton1_.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jRadioButton1_ActionPerformed(evt); } }); getContentPane().add(jRadioButton1_); jRadioButton1_.setBounds(6, 150, 388, 23); jRadioButton2_.setText("jRadioButton2"); jRadioButton2_.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jRadioButton2_ActionPerformed(evt); } }); getContentPane().add(jRadioButton2_); jRadioButton2_.setBounds(6, 176, 388, 23); jRadioButton3_.setText("jRadioButton3"); jRadioButton3_.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jRadioButton3_ActionPerformed(evt); } }); getContentPane().add(jRadioButton3_); jRadioButton3_.setBounds(6, 202, 388, 23); jRadioButton4_.setText("jRadioButton4"); jRadioButton4_.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jRadioButton4_ActionPerformed(evt); } }); getContentPane().add(jRadioButton4_); jRadioButton4_.setBounds(4, 230, 390, 23); jButton_Next_Q.setBackground(new java.awt.Color(255, 153, 102)); jButton_Next_Q.setText("Next"); jButton_Next_Q.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton_Next_QActionPerformed(evt); } }); getContentPane().add(jButton_Next_Q); jButton_Next_Q.setBounds(75, 269, 269, 23); jPanel_Q_Container.setBackground(new java.awt.Color(255, 51, 0)); Lbl_Question.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); Lbl_Question.setText("Question"); javax.swing.GroupLayout jPanel_Q_ContainerLayout = new javax.swing.GroupLayout(jPanel_Q_Container); jPanel_Q_Container.setLayout(jPanel_Q_ContainerLayout); jPanel_Q_ContainerLayout.setHorizontalGroup( jPanel_Q_ContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel_Q_ContainerLayout.createSequentialGroup() .addContainerGap() .addComponent(Lbl_Question, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE) .addContainerGap()) ); jPanel_Q_ContainerLayout.setVerticalGroup( jPanel_Q_ContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel_Q_ContainerLayout.createSequentialGroup() .addContainerGap() .addComponent(Lbl_Question, javax.swing.GroupLayout.DEFAULT_SIZE, 121, Short.MAX_VALUE) .addContainerGap()) ); getContentPane().add(jPanel_Q_Container); jPanel_Q_Container.setBounds(0, 0, 400, 143); jLabel1.setIcon(new javax.swing.ImageIcon("C:\\Users\\USER\\Pictures\\colorful-windows-10-gradient-minimalism-soft-gradient-hd-wallpaper-preview.jpg")); // NOI18N jLabel1.setText("jLabel1"); getContentPane().add(jLabel1); jLabel1.setBounds(0, -3, 400, 310); pack(); }//  private void jButton_Next_QActionPerformed(java.awt.event.ActionEvent evt) { // display the next question Lbl_Question.setText(questions[index]); jRadioButton1_.setText(options[index][0]); jRadioButton2_.setText(options[index][1]); jRadioButton3_.setText(options[index][2]); jRadioButton4_.setText(options[index][3]); bg.clearSelection(); enableRbuttons(true); } private void jRadioButton1_ActionPerformed(java.awt.event.ActionEvent evt) { getSelectedOption(jRadioButton1_); } private void jRadioButton2_ActionPerformed(java.awt.event.ActionEvent evt) { getSelectedOption(jRadioButton2_); } private void jRadioButton3_ActionPerformed(java.awt.event.ActionEvent evt) { getSelectedOption(jRadioButton3_); } private void jRadioButton4_ActionPerformed(java.awt.event.ActionEvent evt) { getSelectedOption(jRadioButton4_); } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new QuizEng().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JLabel Lbl_Question; private javax.swing.JButton jButton_Next_Q; private javax.swing.JLabel jLabel1; private javax.swing.JPanel jPanel_Q_Container; private javax.swing.JRadioButton jRadioButton1_; private javax.swing.JRadioButton jRadioButton2_; private javax.swing.JRadioButton jRadioButton3_; private javax.swing.JRadioButton jRadioButton4_; // End of variables declaration } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

T Sql Window Functions For Data Analysis And Beyond

Authors: Itzik Ben Gan

2nd Edition

0135861446, 978-0135861448

More Books

Students also viewed these Databases questions