QUIZ SYSTEM BY -JOYITA KUNDU BBA STUDENT OF GEORGE GROUP OF COLEGE
Table: LogIn Column Name Type Size ID (Primary Key) Varchar 20 Password Varchar 30 Table:IP Column Name Type Size SNo Integer 11 Questions Varchar 200 a Varchar 100 b Varchar 100 c Varchar 100 d Varchar 100 Result Varchar 1 Table:GK Column Name Type Size SNo Integer 11 Questions Varchar 200 a Varchar 100 b Varchar 100 c Varchar 100 d Varchar 100 Result Varchar 1 Table:Result Column Name Type Size ID Varchar 20 ipresult Varchar 20 gkresult Varchar 20 6.2MenuDesign:
JSS Infoware gateway comprises the following options, organized in a user friendly way. The menu system divided in Menu Bars, each having a pull down menus containing options for a specific task. Sr. Menu Bar PullDownMenu Purpose FormsAttached 1. Select IP Take a test for IP Test.java GK Take a test for GK Test.java 2. Exit QUIT Close application --
6.3 I/O Forms Design & Event Coding: The software project for Public Quiz Management contains various forms along with programming codes. Forms (JFrames) and their event coding are given below. Frame: LogIn.java Codingof LOGIN.java import java.sql.*; public class LogIn extends javax.swing.JFrame { /** Constructor */ public LogIn() { initComponents(); } private void loginBTNActionPerformed(java.awt.event.ActionEvent evt) { String PWord = new String(Password.getPassword()); String Id = ID.getText(); try { Class.forName("java.sql.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/quizdb", "root", "kvuc"); Statement stmt = conn.createStatement();
stmt = conn.createStatement(); String sql = "select * from LogIn where ID = '" + Id + "'"; ResultSet rs = stmt.executeQuery(sql); rs.next(); String str = rs.getString("Password"); if(str.equals(PWord)) { Menu m = new Menu(Id); m.setVisible(true); this.setVisible(false); } else { InvalidLBL.setText("Incorrect ID or Password"); } } catch (Exception e) { InvalidLBL.setText("Incorrect ID or Password");} } private void regLBLMouseClicked(java.awt.event.MouseEvent evt) { Register r = new Register(); r.setVisible(true); this.setVisible(false); } Frame: Register.java
Codingof Register.java import java.sql.*; import javax.swing.JOptionPane; public class Register extends javax.swing.JFrame { /** Constructor */ public Register() { initComponents(); } private void RegisterTFActionPerformed(java.awt.event.ActionEvent evt) { try { Class.forName("java.sql.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/quizdb", "root", "kvuc"); Statement stmt = conn.createStatement(); String sql; sql = "insert into Result values ('" + IDTF.getText() + "',0,0,0,0)"; stmt.executeUpdate(sql); sql = "insert into LogIn values ( '" + IDTF.getText() + "' , '" + PasswordTf.getText() + "' )"; stmt.executeUpdate(sql); stmt.close(); conn.close();
new Menu(IDTF.getText()).setVisible(true); this.setVisible(false); } catch( Exception e) { JOptionPane.showMessageDialog(null,"" + e); } } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Register().setVisible(true); } }); } Frame: Menu.java Coding for Menu.java public class Menu extends javax.swing.JFrame {
String ID; /** Constructor */ public Menu() { initComponents(); } public Menu(String id) { initComponents(); ID = id; } private void startTestBTNActionPerformed(java.awt.event.ActionEvent evt) { String sub = null; if(IP.isSelected()) { sub = "IP"; } else if(GK.isSelected()) { sub = "GK"; } if (sub != null) { Test t = new Test(sub,ID); t.setVisible(true); this.setVisible(false); } } private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) { IP.doClick(); } private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) { GK.doClick(); } private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) { System.exit(0); } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Menu().setVisible(true); } }); } Frame: Test.java
Coding for Test.Java import java.sql.*; import javax.swing.JOptionPane; public class Test extends javax.swing.JFrame { String ID; String Subject; int index =1; int max =0; int result = 0; char [] answers; /** Constructor */ public Test() { initComponents(); } public Test(String subject, String id) { initComponents(); ID = id; Subject = subject; PrevBTN.setVisible(false); try
{Class.forName("java.sql.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/quizdb", "root", "kvuc"); Statement stmt = conn.createStatement(); String sql = "select max(SNo) from " + Subject; ResultSet rs = stmt.executeQuery(sql); rs.next(); max = rs.getInt(1); answers = new char[max]; for(int i=0; i<max;i++) { answers[i] = 'e'; } rs.close(); stmt.close(); conn.close(); getQues(); } catch(Exception r){ JOptionPane.showMessageDialog(null,""+ r); } } private void getQues() { try { Class.forName("java.sql.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/quizdb", "root", "kvuc"); Statement stmt = conn.createStatement(); String sql = "select * from " + Subject + " where SNo = " + index; ResultSet rs = stmt.executeQuery(sql); rs.next(); QuesTA.setText("nQ" + index + ". " + rs.getString(2)); a.setText(rs.getString("a")); b.setText(rs.getString("b")); c.setText(rs.getString("c")); d.setText(rs.getString("d")); a.setSelected(answers[index-1] == 'a'); b.setSelected(answers[index-1] == 'b'); c.setSelected(answers[index-1] == 'c'); d.setSelected(answers[index-1] == 'd'); e.setSelected(answers[index-1] == 'e'); rs.close(); stmt.close(); conn.close();
} catch(Exception r){ JOptionPane.showMessageDialog(null,""+ r); } } private void PrevBTNActionPerformed(java.awt.event.ActionEvent evt) { index--; getQues(); if(index == 1) { PrevBTN.setVisible(false); } if(index < max) { NextBTN.setVisible(true); } } private void NextBTNActionPerformed(java.awt.event.ActionEvent evt) { index++; getQues(); if(index == max) { NextBTN.setVisible(false); } if(index > 1) { PrevBTN.setVisible(true); } } private void bActionPerformed(java.awt.event.ActionEvent evt) { answers[index-1] = 'b'; } private void ResultBTNActionPerformed(java.awt.event.ActionEvent evt) { try { Class.forName("java.sql.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/quizdb", "root", "kvuc"); Statement stmt = conn.createStatement(); String sql = "select Result from " + Subject; ResultSet rs = stmt.executeQuery(sql); int i = 0; while(rs.next()) { char ans = rs.getString(1).charAt(0); if(ans == answers[i]) { result++; } i++; }
float res = ((float)result * 100 ) / max; sql = "Select " + Subject + "Result from Result where ID = '" + ID + "'"; rs = stmt.executeQuery(sql); rs.next(); if(res > rs.getFloat(1)) { sql = "update Result set " + Subject + "Result = " + res + " where ID = '" + ID + "'"; stmt.executeUpdate(sql); } stmt.close(); conn.close(); new Result(res,ID).setVisible(true); this.setVisible(false); } catch(Exception r){ JOptionPane.showMessageDialog(null,r); } } private void aActionPerformed(java.awt.event.ActionEvent evt) { answers[index-1] = 'a'; } private void cActionPerformed(java.awt.event.ActionEvent evt) { answers[index-1] = 'c'; } private void dActionPerformed(java.awt.event.ActionEvent evt) { answers[index-1] = 'd'; } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Test().setVisible(true); } });} Frame: Result.java
Coding of Result.java import java.sql.*; import javax.swing.table.*; import javax.swing.JOptionPane; public class Result extends javax.swing.JFrame { float result; String ID; /** Creates new form Result */ public Result() { initComponents(); } public Result(float res, String id) { initComponents(); result = res; ID = id; Score.setText(res + "%"); try { Class.forName("java.sql.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/quizdb", "root", "kvuc");
Statement stmt = conn.createStatement(); String sql = "select * from Result where ID = '" + ID + "'"; ResultSet rs = stmt.executeQuery(sql); Object[] newrow = new Object[5]; newrow[0] = "MAX MARKS"; rs.next(); for(int i=1; i<=4;i++) { newrow[i] = rs.getString(i+1); } DefaultTableModel tm = (DefaultTableModel)scoreTBL.getModel(); tm.addRow(newrow); } catch (Exception e) { JOptionPane.showMessageDialog(null,"" + e); } } private void BackBTNActionPerformed(java.awt.event.ActionEvent evt) { new Menu(ID).setVisible(true); this.setVisible(false); } private void exitBTNActionPerformed(java.awt.event.ActionEvent evt) { this.dispose(); } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Result().setVisible(true); } });
7. User Manual 7.1HowtoinstallSoftware: Hardware Requirement-  Intel Pentium/Celeron or similar processor based PC at Client/Server end.  128 MB RAM and 4GB HDD space (for Database) is desirable.  Standard I/O devices like Keyboard and Mouse etc.  Printer is needed for hard-copy reports.  Local Area Network(LAN) is required for Client-Server Installation Software Requirement-  Windows 2000/XP OS is desirable.  NetBeans Ver 5.1 or higher should be installed with JDK and JVM.  MySQL Ver 6.1 with Quizdb Database must be present at machine. Database Installation The software project is distributed with a backup copy of a Database named Quizdb with required tables. Some dummy records are present in the tables for testing purposes, which can be deleted before inserting real data. The project is shipped with Quiz.SQL file which installs a database and tables in the computer system. Note: The PC must have MySQL server with user (root) and password (raj) . If root password is any other password, it can be changed by running MySQL Server Instance Configure Wizard. Start Program  MySQL MySQL Server MySQL Server Instance Config Wizard Provide current password of root and new password as “raj” , this will change the root password. To install a MySQL database from a dump file (Quiz.sql) , simply follow the following steps. Step 1: Copy the Quiz.sql file in C:Program filesMysqlMySql server 5.1Bin folder. Step 2: Open MySQL and type the following command to create the dabase named Quizdb. mysql> create database Quizdb; Step 3: Open Command Window (Start Run  cmd) Step 4: Go to the following folder using CD command of DOS. C:Program filesMysqlMySql server 5.1Bin> Step 5: type the following command on above prompt - C:….bin> mysql -u root -praj Quizdb < Quiz.sql This will create a Quizdb databse with required tables.
7.2 Working with SoftwareProject: The Quiz Management Program consists of the following logically organised Menu-structure for the easy functionality. User may choose the menu options for corresponding works. Select: This menu item gives options to select java, html, dbms and networking. Exit: This menu closes the application.
8. References In order to work on this project titled -QUIZ, the following books and literature are refered by me during the various phases of development of the project. (1) The Complete Reference Java 2.0 -by Shildit (2)MySQL, Black Book -by Steven Holzner (2) Understanding SQL – Gruber (3) http://www.mysql.org/ (4) http://www.netbeans.org/ (5) On-line Help of NetBeans ® (6) Informatics Practices for class XII -by Sumita Arora (7) Together with Informatics Practices (6) Various Websites of Discussion Forum and software development activities. Other than the above-mentioned books, the suggestions and supervision of my teacher and my class experience also helped me to develop this software project.

code for quiz in my sql

  • 1.
    QUIZ SYSTEM BY -JOYITAKUNDU BBA STUDENT OF GEORGE GROUP OF COLEGE
  • 2.
    Table: LogIn Column NameType Size ID (Primary Key) Varchar 20 Password Varchar 30 Table:IP Column Name Type Size SNo Integer 11 Questions Varchar 200 a Varchar 100 b Varchar 100 c Varchar 100 d Varchar 100 Result Varchar 1 Table:GK Column Name Type Size SNo Integer 11 Questions Varchar 200 a Varchar 100 b Varchar 100 c Varchar 100 d Varchar 100 Result Varchar 1 Table:Result Column Name Type Size ID Varchar 20 ipresult Varchar 20 gkresult Varchar 20 6.2MenuDesign:
  • 3.
    JSS Infoware gatewaycomprises the following options, organized in a user friendly way. The menu system divided in Menu Bars, each having a pull down menus containing options for a specific task. Sr. Menu Bar PullDownMenu Purpose FormsAttached 1. Select IP Take a test for IP Test.java GK Take a test for GK Test.java 2. Exit QUIT Close application --
  • 4.
    6.3 I/O FormsDesign & Event Coding: The software project for Public Quiz Management contains various forms along with programming codes. Forms (JFrames) and their event coding are given below. Frame: LogIn.java Codingof LOGIN.java import java.sql.*; public class LogIn extends javax.swing.JFrame { /** Constructor */ public LogIn() { initComponents(); } private void loginBTNActionPerformed(java.awt.event.ActionEvent evt) { String PWord = new String(Password.getPassword()); String Id = ID.getText(); try { Class.forName("java.sql.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/quizdb", "root", "kvuc"); Statement stmt = conn.createStatement();
  • 5.
    stmt = conn.createStatement(); Stringsql = "select * from LogIn where ID = '" + Id + "'"; ResultSet rs = stmt.executeQuery(sql); rs.next(); String str = rs.getString("Password"); if(str.equals(PWord)) { Menu m = new Menu(Id); m.setVisible(true); this.setVisible(false); } else { InvalidLBL.setText("Incorrect ID or Password"); } } catch (Exception e) { InvalidLBL.setText("Incorrect ID or Password");} } private void regLBLMouseClicked(java.awt.event.MouseEvent evt) { Register r = new Register(); r.setVisible(true); this.setVisible(false); } Frame: Register.java
  • 6.
    Codingof Register.java import java.sql.*; importjavax.swing.JOptionPane; public class Register extends javax.swing.JFrame { /** Constructor */ public Register() { initComponents(); } private void RegisterTFActionPerformed(java.awt.event.ActionEvent evt) { try { Class.forName("java.sql.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/quizdb", "root", "kvuc"); Statement stmt = conn.createStatement(); String sql; sql = "insert into Result values ('" + IDTF.getText() + "',0,0,0,0)"; stmt.executeUpdate(sql); sql = "insert into LogIn values ( '" + IDTF.getText() + "' , '" + PasswordTf.getText() + "' )"; stmt.executeUpdate(sql); stmt.close(); conn.close();
  • 7.
    new Menu(IDTF.getText()).setVisible(true); this.setVisible(false); } catch( Exceptione) { JOptionPane.showMessageDialog(null,"" + e); } } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Register().setVisible(true); } }); } Frame: Menu.java Coding for Menu.java public class Menu extends javax.swing.JFrame {
  • 8.
    String ID; /** Constructor*/ public Menu() { initComponents(); } public Menu(String id) { initComponents(); ID = id; } private void startTestBTNActionPerformed(java.awt.event.ActionEvent evt) { String sub = null; if(IP.isSelected()) { sub = "IP"; } else if(GK.isSelected()) { sub = "GK"; } if (sub != null) { Test t = new Test(sub,ID); t.setVisible(true); this.setVisible(false); } } private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) { IP.doClick(); } private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) { GK.doClick(); } private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) { System.exit(0); } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Menu().setVisible(true); } }); } Frame: Test.java
  • 9.
    Coding for Test.Java importjava.sql.*; import javax.swing.JOptionPane; public class Test extends javax.swing.JFrame { String ID; String Subject; int index =1; int max =0; int result = 0; char [] answers; /** Constructor */ public Test() { initComponents(); } public Test(String subject, String id) { initComponents(); ID = id; Subject = subject; PrevBTN.setVisible(false); try
  • 10.
    {Class.forName("java.sql.Driver"); Connection conn =DriverManager.getConnection("jdbc:mysql://localhost/quizdb", "root", "kvuc"); Statement stmt = conn.createStatement(); String sql = "select max(SNo) from " + Subject; ResultSet rs = stmt.executeQuery(sql); rs.next(); max = rs.getInt(1); answers = new char[max]; for(int i=0; i<max;i++) { answers[i] = 'e'; } rs.close(); stmt.close(); conn.close(); getQues(); } catch(Exception r){ JOptionPane.showMessageDialog(null,""+ r); } } private void getQues() { try { Class.forName("java.sql.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/quizdb", "root", "kvuc"); Statement stmt = conn.createStatement(); String sql = "select * from " + Subject + " where SNo = " + index; ResultSet rs = stmt.executeQuery(sql); rs.next(); QuesTA.setText("nQ" + index + ". " + rs.getString(2)); a.setText(rs.getString("a")); b.setText(rs.getString("b")); c.setText(rs.getString("c")); d.setText(rs.getString("d")); a.setSelected(answers[index-1] == 'a'); b.setSelected(answers[index-1] == 'b'); c.setSelected(answers[index-1] == 'c'); d.setSelected(answers[index-1] == 'd'); e.setSelected(answers[index-1] == 'e'); rs.close(); stmt.close(); conn.close();
  • 11.
    } catch(Exception r){ JOptionPane.showMessageDialog(null,""+r); } } private void PrevBTNActionPerformed(java.awt.event.ActionEvent evt) { index--; getQues(); if(index == 1) { PrevBTN.setVisible(false); } if(index < max) { NextBTN.setVisible(true); } } private void NextBTNActionPerformed(java.awt.event.ActionEvent evt) { index++; getQues(); if(index == max) { NextBTN.setVisible(false); } if(index > 1) { PrevBTN.setVisible(true); } } private void bActionPerformed(java.awt.event.ActionEvent evt) { answers[index-1] = 'b'; } private void ResultBTNActionPerformed(java.awt.event.ActionEvent evt) { try { Class.forName("java.sql.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/quizdb", "root", "kvuc"); Statement stmt = conn.createStatement(); String sql = "select Result from " + Subject; ResultSet rs = stmt.executeQuery(sql); int i = 0; while(rs.next()) { char ans = rs.getString(1).charAt(0); if(ans == answers[i]) { result++; } i++; }
  • 12.
    float res =((float)result * 100 ) / max; sql = "Select " + Subject + "Result from Result where ID = '" + ID + "'"; rs = stmt.executeQuery(sql); rs.next(); if(res > rs.getFloat(1)) { sql = "update Result set " + Subject + "Result = " + res + " where ID = '" + ID + "'"; stmt.executeUpdate(sql); } stmt.close(); conn.close(); new Result(res,ID).setVisible(true); this.setVisible(false); } catch(Exception r){ JOptionPane.showMessageDialog(null,r); } } private void aActionPerformed(java.awt.event.ActionEvent evt) { answers[index-1] = 'a'; } private void cActionPerformed(java.awt.event.ActionEvent evt) { answers[index-1] = 'c'; } private void dActionPerformed(java.awt.event.ActionEvent evt) { answers[index-1] = 'd'; } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Test().setVisible(true); } });} Frame: Result.java
  • 13.
    Coding of Result.java importjava.sql.*; import javax.swing.table.*; import javax.swing.JOptionPane; public class Result extends javax.swing.JFrame { float result; String ID; /** Creates new form Result */ public Result() { initComponents(); } public Result(float res, String id) { initComponents(); result = res; ID = id; Score.setText(res + "%"); try { Class.forName("java.sql.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/quizdb", "root", "kvuc");
  • 14.
    Statement stmt =conn.createStatement(); String sql = "select * from Result where ID = '" + ID + "'"; ResultSet rs = stmt.executeQuery(sql); Object[] newrow = new Object[5]; newrow[0] = "MAX MARKS"; rs.next(); for(int i=1; i<=4;i++) { newrow[i] = rs.getString(i+1); } DefaultTableModel tm = (DefaultTableModel)scoreTBL.getModel(); tm.addRow(newrow); } catch (Exception e) { JOptionPane.showMessageDialog(null,"" + e); } } private void BackBTNActionPerformed(java.awt.event.ActionEvent evt) { new Menu(ID).setVisible(true); this.setVisible(false); } private void exitBTNActionPerformed(java.awt.event.ActionEvent evt) { this.dispose(); } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Result().setVisible(true); } });
  • 15.
    7. User Manual 7.1HowtoinstallSoftware: HardwareRequirement-  Intel Pentium/Celeron or similar processor based PC at Client/Server end.  128 MB RAM and 4GB HDD space (for Database) is desirable.  Standard I/O devices like Keyboard and Mouse etc.  Printer is needed for hard-copy reports.  Local Area Network(LAN) is required for Client-Server Installation Software Requirement-  Windows 2000/XP OS is desirable.  NetBeans Ver 5.1 or higher should be installed with JDK and JVM.  MySQL Ver 6.1 with Quizdb Database must be present at machine. Database Installation The software project is distributed with a backup copy of a Database named Quizdb with required tables. Some dummy records are present in the tables for testing purposes, which can be deleted before inserting real data. The project is shipped with Quiz.SQL file which installs a database and tables in the computer system. Note: The PC must have MySQL server with user (root) and password (raj) . If root password is any other password, it can be changed by running MySQL Server Instance Configure Wizard. Start Program  MySQL MySQL Server MySQL Server Instance Config Wizard Provide current password of root and new password as “raj” , this will change the root password. To install a MySQL database from a dump file (Quiz.sql) , simply follow the following steps. Step 1: Copy the Quiz.sql file in C:Program filesMysqlMySql server 5.1Bin folder. Step 2: Open MySQL and type the following command to create the dabase named Quizdb. mysql> create database Quizdb; Step 3: Open Command Window (Start Run  cmd) Step 4: Go to the following folder using CD command of DOS. C:Program filesMysqlMySql server 5.1Bin> Step 5: type the following command on above prompt - C:….bin> mysql -u root -praj Quizdb < Quiz.sql This will create a Quizdb databse with required tables.
  • 16.
    7.2 Working withSoftwareProject: The Quiz Management Program consists of the following logically organised Menu-structure for the easy functionality. User may choose the menu options for corresponding works. Select: This menu item gives options to select java, html, dbms and networking. Exit: This menu closes the application.
  • 17.
    8. References In orderto work on this project titled -QUIZ, the following books and literature are refered by me during the various phases of development of the project. (1) The Complete Reference Java 2.0 -by Shildit (2)MySQL, Black Book -by Steven Holzner (2) Understanding SQL – Gruber (3) http://www.mysql.org/ (4) http://www.netbeans.org/ (5) On-line Help of NetBeans ® (6) Informatics Practices for class XII -by Sumita Arora (7) Together with Informatics Practices (6) Various Websites of Discussion Forum and software development activities. Other than the above-mentioned books, the suggestions and supervision of my teacher and my class experience also helped me to develop this software project.