i am trying to make some sort of quiz and meet with some problems, this is the kind of quiz where each option is given a certain points and at the end of the quiz, the score is tallied up to see how well you do. the problem right now is the scores does not add up no matter what i try. i managed to get some sort of output but its kinda not working at all. i have a sample of 3 questions right now and the "Total number of As selected:" would only show the option selected for question3 and the " total score" would only calculate the sum for question2.
this is the .java which i have right now
import javax.swing.*; import java.awt.*; import java.sql.*; import java.text.*; import java.awt.event.*; public class assignTips implements ActionListener { JFrame que1 = new JFrame(); JFrame que2 = new JFrame(); JFrame que3 = new JFrame(); JFrame res1 = new JFrame(); JLabel label1= new JLabel("1.Question to be filled eventually :"); JLabel label2= new JLabel("2.Question to be filled eventually:"); JLabel label3= new JLabel("3.Question to be filled eventually:"); JLabel label4= new JLabel(); JLabel label91= new JLabel(); JLabel label96= new JLabel(); JLabel label97= new JLabel(); JLabel label98= new JLabel(); JLabel label99= new JLabel(); JLabel labelname= new JLabel("enter your name"); JTextField textname = new JTextField(); JRadioButton a=new JRadioButton("a.option1"); JRadioButton b=new JRadioButton("b.option2"); JRadioButton c=new JRadioButton("c.option3"); JRadioButton a2=new JRadioButton("a.option1"); JRadioButton b2=new JRadioButton("b.option2"); JRadioButton c2=new JRadioButton("c.option3"); JRadioButton a3=new JRadioButton("a.option1"); JRadioButton b3=new JRadioButton("b.option2"); JRadioButton c3=new JRadioButton("c.option3"); JButton button=new JButton("NEXT"); JButton button2=new JButton("NEXT"); JButton button4=new JButton("NEXT"); JButton button3=new JButton("Click to submit your score"); ButtonGroup g=new ButtonGroup(); // @jve:decl-index=0: public assignTips() { que1.setLayout(new FlowLayout()); que1.setSize(400,300); que1.setLayout(new GridLayout(8,8)); que1.setResizable(true); que1.setTitle("Question1"); que1.getContentPane().add(label1); que1.getContentPane().add(a); que1.getContentPane().add(b); que1.getContentPane().add(c); que1.getContentPane().add(button); a.addActionListener(this); b.addActionListener(this); c.addActionListener(this); button.addActionListener(this); g.add(a); g.add(b); g.add(c); que1.setVisible(true); que1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); que2.setLayout(new FlowLayout()); que2.setSize(400,300); que2.setLayout(new GridLayout(8,8)); que2.setResizable(true); que2.setTitle("Question2"); que2.getContentPane().add(label2); que2.getContentPane().add(a2); que2.getContentPane().add(b2); que2.getContentPane().add(c2); que2.getContentPane().add(button2); a2.addActionListener(this); b2.addActionListener(this); c2.addActionListener(this); button2.addActionListener(this); g.add(a2); g.add(b2); g.add(c2); que3.setLayout(new FlowLayout()); que3.setSize(400,300); que3.setLayout(new GridLayout(8,8)); que3.setResizable(true); que3.setTitle("Question3"); que3.getContentPane().add(label3); que3.getContentPane().add(a3); que3.getContentPane().add(b3); que3.getContentPane().add(c3); que3.getContentPane().add(button4); a3.addActionListener(this); b3.addActionListener(this); c3.addActionListener(this); button4.addActionListener(this); g.add(a3); g.add(b3); g.add(c3); res1.setLayout(new FlowLayout()); res1.setSize(400,300); res1.setLayout(new GridLayout(8,8)); res1.setResizable(true); res1.setTitle("Result"); res1.getContentPane().add(label99); res1.getContentPane().add(label98); res1.getContentPane().add(label97); res1.getContentPane().add(label96); res1.getContentPane().add(labelname); res1.getContentPane().add(textname); res1.getContentPane().add(button3); button3.setActionCommand("button3"); button3.addActionListener(this); que1.setVisible(true); que3.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main(String[] args) { new assignTips(); } public void actionPerformed(ActionEvent e) { Object source = e.getSource(); int que1a=0,que1b=0,que1c=0; int que2a=0,que2b=0,que2c=0; int que3a=0,que3b=0,que3c=0; if (a.isSelected()) { que1a++; } else if(b.isSelected()) { que1b++; } else if(c.isSelected()) { que1c++; } if(a2.isSelected()) { que2a++; } else if(b2.isSelected()) { que2b++; } else if(c2.isSelected()) { que2c++; } if(a3.isSelected()) { que3a++; } else if(b3.isSelected()) { que3b++; } else if(c3.isSelected()) { que3c++; } int totala=que1a + que2a +que3a; int totalb=que1b + que2b +que3b; int totalc=que1c + que2c +que3c; int totaltotal=(totala*3)+(totalb*2)+totalc; if(source==button) { que1.setVisible(false); que2.setVisible(true); que3.setVisible(false); } if(source==button2) { que2.setVisible(false); que3.setVisible(true); } if(source==button4) { que3.setVisible(false); res1.setVisible(true); } label99.setText("Total number of As selected: " + totala); label98.setText("Total number of Bs selected: " + totalb); label97.setText("Total number of Cs selected: " + totalc); totaltotal=(totala*3)+(totalb*2)+totalc; if(source==button2) { label96.setText("Your total Score:" + totaltotal); label91.setText(""+ totaltotal); } String cmd = e.getActionCommand(); if(cmd.equals("button3")) { insertData();} } private void insertData() { Connection con; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection("jdbc:odbc:tips"); String sql = "Insert Into Table1 (NameParticipant,Score) " + "Values ('"+textname.getText()+"','"+label91.getText() +"')"; Statement statement = con.createStatement(); statement.execute(sql); } catch(Exception e1) { System.out.println("error"); } } }