Hello Guys! Im developing a Quiz System for a game which i LOVE alot. Have done most of the work but still need some help from you guys! Problem faced is when the contestant answers it correctly the counter is not incremented and they are refusing to be passed into the parameters. The code is as follows:

This is the MKDAO file which is an interface. Methods are inherited from here

package DataAccessObject;

import java.sql.SQLException;
import java.util.ArrayList;

/**
 *
 * @author Sagu Wesker
 */
public interface MKDAO {
    
    public boolean ContestantValidation(String Username  , String Password , String Role)
            throws ClassNotFoundException , SQLException;
    
    public boolean AdministratorValidation(String Username , String Password , String Role)
            throws ClassNotFoundException , SQLException;
    
    void AddQuestion(String QuestionID , String QuestionDetails  , String FirstAnswer , String SecondAnswer , String ThirdAnswer , String FourthAnswer , String CorrectAnswer , int DifficultyID)
            throws ClassNotFoundException , SQLException;
    
    void UpdateQuestion(String QuestionID , String QuestionDetails , String FirstAnswer , String SecondAnswer , String ThirdAnswer , String FourthAnswer , String CorrectAnswer , int DifficultyID)
            throws ClassNotFoundException , SQLException;
    
    void DeleteQuestion(int QuestionID)
            throws ClassNotFoundException , SQLException;
    
    ArrayList<QuestionRecordViews> getQuestions()
            throws ClassNotFoundException , SQLException;
    
}

This is the DAO file which has all the connections to the Database. etc etc

package DataAccessObject;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

/**
 *
 * @author Sagu Wesker
 */
public class DAO implements MKDAO {
    
    public DAO() 
    {
        
    }
    
    public static MKDAO DAOInterface = null;
    
    public Connection SQLConnection = null;
    
    
    public static MKDAO getDAOInterface()
    {
        if(DAOInterface == null)
        {
            DAOInterface = new DAO();
        }
        
        return DAOInterface;
    }
    
    public Statement EstablishDatabaseConnection()
            throws ClassNotFoundException , SQLException
    {
        try
        {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            String SQLEstablisher = new String("jdbc:odbc:Nekropolis");
            SQLConnection = DriverManager.getConnection(SQLEstablisher , " " , " ");
            return SQLConnection.createStatement();
            
        }
        
        catch (ClassNotFoundException CNFE)
        {
            System.out.println(CNFE);
            throw CNFE;
        }
        
        catch (SQLException SQLE)
        {
            System.out.println(SQLE);
            throw SQLE;
        }
        
    }
    
    public void ConnectionDestroyer()
            throws SQLException
    {
        try
        {
            SQLConnection.close();   
        }
        
        catch (SQLException SQLE)
        {
            System.out.println(SQLE);
            throw SQLE;
        }
    }
    
    private ContestantRecordViews populateContestantObject(ResultSet Results)
            throws ClassNotFoundException , SQLException
    {
        int ContestantID = Results.getInt("ContestantID");
        String FirstName = Results.getString("FirstName");
        String MiddleName = Results.getString("MiddleName");
        String LastName = Results.getString("LastName");
        String EMail = Results.getString("EMail");
        String Mobile = Results.getString("Mobile");
        String Username = Results.getString("Username");
        String Role = Results.getString("Role");
        
        return new ContestantViews(ContestantID, FirstName, MiddleName, LastName, EMail, Mobile, Username, Role);
    }
    
    private QuestionRecordViews populateQuestionObject(ResultSet Results)
            throws ClassNotFoundException , SQLException
    {
        int QuestionID = Results.getInt("QuestionID");
        String QuestionDetails = Results.getString("QuestionDetails");
        String FirstAnswer = Results.getString("FirstAnswer");
        String SecondAnswer = Results.getString("SecondAnswer");
        String ThirdAnswer = Results.getString("ThirdAnswer");
        String FourthAnswer = Results.getString("FourthAnswer");
        String CorrectAnswer = Results.getString("CorrectAnswer");
        int DifficultyID = Results.getInt("DifficultyID");
        
        return new QuestionViews(QuestionID, QuestionDetails, FirstAnswer, SecondAnswer, ThirdAnswer, FourthAnswer, CorrectAnswer, DifficultyID);
    }
    
    public boolean ContestantValidation(String Username , String Password , String Role)
            throws ClassNotFoundException , SQLException
    {
        try
        {
            Statement SQLStatement = EstablishDatabaseConnection();
            String SQLQuery = "SELECT * FROM Contestant " + "WHERE Username = '" + Username + "'" + "AND Password = '" + Password + "'" + "AND Role = '" + Role + "'";
            ResultSet LoginResult = SQLStatement.executeQuery(SQLQuery);
            
            if(LoginResult.next())
            {
                ConnectionDestroyer();
                return true;
            }
            
                ConnectionDestroyer();
                return false;
        }
        
        catch (ClassNotFoundException CNFE)
        {
            System.out.println(CNFE);
            throw CNFE;
        }
        
        catch (SQLException SQLE)
        {
            System.out.print(SQLE);
            throw SQLE;
        }
    }
    
        public boolean AdministratorValidation(String Username , String Password , String Role)
            throws ClassNotFoundException , SQLException
    {
        try
        {
            Statement SQLStatement = EstablishDatabaseConnection();
            String SQLQuery = "SELECT * FROM Administrator WHERE Username = '"+ Username +"' , Password = '" + Password +"' , AND Role = '" + Role +"'";
            ResultSet LoginResult = SQLStatement.executeQuery(SQLQuery);
            
            if(LoginResult.next())
            {
                ConnectionDestroyer();
                return true;
            }
            
                ConnectionDestroyer();
                return false;
        }
        
        catch (ClassNotFoundException CNFE)
        {
            System.out.println(CNFE);
            throw CNFE;
        }
        
        catch (SQLException SQLE)
        {
            System.out.print(SQLE);
            throw SQLE;
        }
    }
        
        public void AddQuestion(String QuestionID , String QuestionDetails , String FirstAnswer , String SecondAnswer , String ThirdAnswer , String FourthAnswer , String CorrectAnswer , int DifficultyID)
                throws ClassNotFoundException , SQLException
        {
            try
            {
                Statement SQLStatement = EstablishDatabaseConnection();
                String SQLQuery = "INSERT INTO Question(QuestionDetails , FirstAnswer , SecondAnswer , ThirdAnswer , FourthAnswer , CorrectAnswer , DifficultyID) VALUES('" + QuestionDetails +"' , '" + FirstAnswer +"' , '" + SecondAnswer +"' , '" + ThirdAnswer +"' , '" + FourthAnswer +"' , '" + CorrectAnswer +"' , '" + DifficultyID +"')";
                SQLStatement.executeUpdate(SQLQuery);
                ConnectionDestroyer();
            }
            
            catch (ClassNotFoundException CNFE)
            {
                System.out.println(CNFE);
                throw CNFE;
            }
            
            catch (SQLException SQLE)
            {
                System.out.println(SQLE);
                throw SQLE;
            }
        }
        
        public void UpdateQuestion(String QuestionID , String QuestionDetails , String FirstAnswer , String SecondAnswer , String ThirdAnswer , String FourthAnswer , String CorrectAnswer , int DifficultyID)
                throws ClassNotFoundException , SQLException
        {
            try
            {
                Statement SQLStatement = EstablishDatabaseConnection();
                String SQLQuery = "UPDATE Question SET QuestionDetails = '" + QuestionDetails +"' , '" + FirstAnswer +"' , '" + SecondAnswer +"' , '" + ThirdAnswer +"' , '" + FourthAnswer +"' , '" + CorrectAnswer +"' , '" + DifficultyID +"' WHERE QuestionID = " + QuestionID ;
                SQLStatement.executeUpdate(SQLQuery);
                ConnectionDestroyer();
            }
            
            catch (ClassNotFoundException CNFE)
            {
                System.out.println(CNFE);
                throw CNFE;
            }
            
            catch (SQLException SQLE)
            {
                System.out.println(SQLE);
                throw SQLE;
            }
            

        }
        
        public void DeleteQuestion(int QuestionID)
               throws ClassNotFoundException , SQLException
        {
            try
            {
                Statement SQLStatement = EstablishDatabaseConnection();
                String SQLQuery = "DELETE * FROM Questions WHERE QuestionID  = " + QuestionID;
                SQLStatement.executeUpdate(SQLQuery);
                ConnectionDestroyer();
            }
            
            catch (ClassNotFoundException CNFE)
            {
                System.out.println(CNFE);
                throw CNFE;
            }
            
            catch (SQLException SQLE)
            {
                System.out.println(SQLE);
                throw SQLE;
            }
        }
        
        public ArrayList<QuestionRecordViews> getQuestions()
                throws ClassNotFoundException , SQLException
        {
            try
            {
                ArrayList<QuestionRecordViews> QuestionRecord = new ArrayList<QuestionRecordViews>();
                Statement SQLStatement = EstablishDatabaseConnection();
                String SQLQuery = "SELECT * FROM Question;";
                ResultSet QuestionRS = SQLStatement.executeQuery(SQLQuery);
                
                while(QuestionRS.next())
                {
                    QuestionRecord.add(populateQuestionObject(QuestionRS));
                }
                
                ConnectionDestroyer();
                return QuestionRecord;
            }
            
            catch (ClassNotFoundException CNFE)
            {
                System.out.println(CNFE);
                throw CNFE;
            }
            
            catch (SQLException SQLE)
            {
                System.out.println(SQLE);
                throw SQLE;
            }
        }
    
}
package DataAccessObject;

/**
 *
 * @author Sagu Wesker
 */
public class QuestionViews implements QuestionRecordViews 

{
    private int QuestionID;
    private String QuestionDetails;
    private String FirstAnswer;
    private String SecondAnswer;
    private String ThirdAnswer;
    private String FourthAnswer;
    private String CorrectAnswer;
    private int DifficultyID;
    
    public QuestionViews()
    {
        
    }
    
    public QuestionViews(int QuestionID , String QuestionDetails , String FirstAnswer , String SecondAnswer , String ThirdAnswer , String FourthAnswer , String CorrectAnswer , int DifficultyID)
    {
        this.QuestionID = QuestionID;
        this.QuestionDetails = QuestionDetails;
        this.FirstAnswer = FirstAnswer;
        this.SecondAnswer = SecondAnswer;
        this.ThirdAnswer = ThirdAnswer;
        this.FourthAnswer = FourthAnswer;
        this.CorrectAnswer = CorrectAnswer;
        this.DifficultyID = DifficultyID;
    }
    
    public int getQuestionID()
    {
        return QuestionID;
    }
    
    public void setQuestionID(int QuestionID)
    {
        this.QuestionID = QuestionID;
    }
    
    public String getQuestionDetails()
    {
        return QuestionDetails;
    }
    
    public void setQuestionDetails(String QuestionDetails)
    {
        this.QuestionDetails = QuestionDetails;    
    }
    
    public String getFirstAnswer()
    {
        return FirstAnswer;
    }
    
    public void setFirstAnswer(String FirstAnswer)
    {
        this.FirstAnswer = FirstAnswer;
    }
    
    public String getSecondAnswer()
    {
        return SecondAnswer;
    }
    
    public void setSecondAnswer(String SecondAnswer)
    {
        this.SecondAnswer = SecondAnswer;
    }
    
    public String getThirdAnswer()
    {
        return ThirdAnswer;
    }
    
    public void setThirdAnswer(String ThirdAnswer)
    {
        this.ThirdAnswer = ThirdAnswer;
    }
    
    public String getFourthAnswer()
    {
        return FourthAnswer;
    }
    
    public void setFourthAnswer(String FourthAnswer)
    {
        this.FourthAnswer = FourthAnswer;
    }
    
    public String getCorrectAnswer()
    {
        return CorrectAnswer;
    }
    
    public void setCorrectAnswer(String CorrectAnswer)
    {
        this.CorrectAnswer = CorrectAnswer;
    }
    
    public int getDifficultyID()
    {
        return DifficultyID;
    }
    
    public void setDifficultyID(int DifficultyID)
    {
        this.DifficultyID = DifficultyID;
    }
    





}

The one above is getter and setter methods

package DataAccessObject;

/**
 *
 * @author Sagu Wesker
 */
public interface QuestionRecordViews 

{
    public int getQuestionID();
    
    public void setQuestionID(int QuestionID);
    
    public String getQuestionDetails();
    
    public void setQuestionDetails(String QuestionDetails);
    
    public String getFirstAnswer();
    
    public void setFirstAnswer(String FirstAnswer);
    
    public String getSecondAnswer();
    
    public void setSecondAnswer(String SecondAnswer);
    
    public String getThirdAnswer();
    
    public void setThirdAnswer(String ThirdAnswer);
    
    public String getFourthAnswer();
    
    public void setFourthAnswer(String FourthAnswer);
    
    public String getCorrectAnswer();
    
    public void setCorrectAnswer(String CorrectAnswer);
    
    public int getDifficultyID();
    
    public void setDifficultyID(int DifficultyID);








}

The JSP File where the questions are shown and from where i want the count to be be incremented and be accepted in the parameter in accordance to the questions answered by the contestant

<%-- 
    Document   : Novice
    Created on : Dec 25, 2011, 1:09:37 PM
    Author     : Sagu Wesker
--%>

<%@page import="DataAccessObject.QuestionRecordViews"%>
<%@page import="java.util.ArrayList"%>
<%@page import="DataAccessObject.DAO"%>
<%@page import="DataAccessObject.MKDAO"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="QuizCSS/MK.css" rel="stylesheet" type="text/css" />
        <link href="QuizJavaScript/ddsmoothmenu-v.css" rel="stylesheet" type="text/css" />
        <link href="QuizJavaScript/ddsmoothmenu.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="QuizJavaScript/jquery.easing.1.3.js"></script>
        <script type="text/javascript" src="QuizJavaScript/js_min.js"></script>
        <script type="text/javascript" src="QuizJavaScript/jsapi.js"></script>
        <script src="Scripts/swfobject_modified.js" type="text/javascript"></script>
        <script type="text/javascript" src="QuizJavaScript/ddsmoothmenu.js"></script>
        <script type="text/javascript" src="QuizJavaScript/jquery.min.js"></script>
        
        <script type="text/javascript">

ddsmoothmenu.init({
	mainmenuid: "smoothmenu1", //menu DIV id
	orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
	classname: 'ddsmoothmenu', //class added to menu's outer DIV
	//customtheme: ["#1c5a80", "#18374a"],
	contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
})

ddsmoothmenu.init({
	mainmenuid: "smoothmenu2", //Menu DIV id
	orientation: 'v', //Horizontal or vertical menu: Set to "h" or "v"
	classname: 'ddsmoothmenu-v', //class added to menu's outer DIV
	//customtheme: ["#804000", "#482400"],
	contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
})

</script>
<title>Novice Battle Tower</title>
</head>
<body bgcolor="#000000">
    
<%
            
//String UserSession=(String)session.getAttribute("Role");
            
//if (UserSession == null ? "Role" != null : !UserSession.equals("Contestant"))
//{
   //response.sendRedirect("AccessDenied.jsp");
//}        
%>    

<center>
    
<div id="smoothmenu1" class="ddsmoothmenu">
    
<ul>
    
<li><a href="ChooseYourDestiny.jsp">Begin The Tournament</a>
    
</li>

<li><a href="#">View Your</a>
    
<ul>
    
<li><a href="ContestantProfile.jsp">Profile Details</a></li>

<li><a href="ContestantPerformance.jsp">Performance</a></li>

</ul>
    
</li>

<li><a href="Ranks.jsp">View Your Ranks</a>
    
</li>

<li><a href="GameOver.jsp">Exit The Outworld Portal</a></li>

</ul>
    
<br style="clear: left" />

</div>
    
<center>
        
    <%
    MKDAO Dao = DAO.getDAOInterface();
    
    ArrayList GetQuestions = Dao.getQuestions();
    
    int Counter = 0;
    
    if(request.getParameter("Counter") != null)
    {
        
        Counter = Integer.parseInt(request.getParameter("Counter"));
    
    }
    
    if(Counter==GetQuestions.size())
    {
        
        response.sendRedirect("TournamentOutcome.jsp");
    
    }
    
    else
    {
        
    QuestionRecordViews Questions = (QuestionRecordViews)GetQuestions.get(Counter);
        
    String CorrectAnswer = Questions.getCorrectAnswer();
    
    int Right = 0;
        
    String Correct = Integer.toString(Right);
    
    session.setAttribute("Correct", Right);
        
    int Count = 0;
        
    if(request.getParameter("Count") != null)
        
    {
        
    Count = Integer.parseInt(request.getParameter("Count"));
    
    }
        
    session.setAttribute("Count", Count);
        
    String Answer = request.getParameter("Answer");
        
    session.setAttribute("Answer", Answer);
        
    if(request.getParameter("Answer") == null)
        
    {
        
    Answer = request.getParameter("Answer");
    
    }
        
    String getCorrectAnswer = request.getParameter("CorrectAnswer");
        
        //String Points = Integer.toString(RightAnswer);

    %>
    
    <form name="NoviceQuiz" method="post">
    
    <table border="1" cellpadding="4" cellspacing="0" class="MainBody" align="center" style="border-color: white">

    <tr>
        
    <td colspan="2" style="width: 350px; text-align: center"><img src="QuizImages/SPLASH.BMP" width="400px" height="400px">
        
    <h2 style="color: white">Novice Quiz</h2>
        
    </td>
    
    </tr>
    
    <tr>
        
    <td width="120" height="6" align="left" style="font-family: Cambria; color: white; font-size: 18px">
        
    Question ID    
        
    </td>
    
    <td width="234" height="6" align="" style="font-family: Cambria; color: white; font-size: 18px">
        
    <p class="h3quizstyle"><%=Questions.getQuestionID()%></p>   
        
    </td>
        
    </tr>
    
    <tr>
        
    <td width="120" height="6" align="left" style="font-family: Cambria; color: white; font-size: 18px">
        
    Question    
        
    </td>
    
    <td width="234" height="6" align="left" style="font-family: Cambria; color: white; font-size: 18px">
        
    <p class="h3quizstyle"><%=Questions.getQuestionDetails()%></p>    
        
    </td>
        
    </tr>
    
    <tr>
        
    <td width="120" height="6" align="left" style="font-family: Cambria; color: white; font-size: 18px">
        
    Choice A    
        
    </td>
    
    <td width="234" height="6" align="left" style="font-family: Cambria; color: white; font-size: 18px">
        
    <input name="Answer" type="radio" value="<%=Questions.getFirstAnswer()%>" /><p class="h3quizstyle"><%=Questions.getFirstAnswer()%></p>    
        
    </td>
        
    </tr>
    
    <tr>
        
    <td width="120" height="6" align="left" style="font-family: Cambria; color: white; font-size: 18px">
        
    Choice B    
        
    </td>
    
    <td width="234" height="6" align="left" style="font-family: Cambria; color: white; font-size: 18px">
        
    <input name="Answer" type="radio" value="<%=Questions.getSecondAnswer()%>" /><p class="h3quizstyle"><%=Questions.getSecondAnswer()%></p>    
        
    </td>
        
    </tr>
    
    <tr>
        
    <td width="120" height="6" align="left" style="font-family: Cambria; color: white; font-size: 18px">
        
    Choice C    
        
    </td>
    
    <td width="234" height="6" align="left" style="font-family: Cambria; color: white; font-size: 18px">
        
    <input name="Answer" type="radio" value="<%=Questions.getThirdAnswer()%>" /><p class="h3quizstyle"><%=Questions.getThirdAnswer()%></p>    
        
    </td>
        
    </tr>
    
    <tr>
        
    <td width="120" height="6" align="left" style="font-family: Cambria; color: white; font-size: 18px">
        
    Choice D    
        
    </td>
    
    <td width="234" height="6" align="left" style="font-family: Cambria; color: white; font-size: 18px">
        
    <input name="Answer" type="radio" value="<%=Questions.getFourthAnswer()%>" /><p class="h3quizstyle"><%=Questions.getFourthAnswer()%></p>    
        
    <input type="hidden" name="CorrectAnswer" value="<%=Questions.getCorrectAnswer()%>" />
    
        <%        
    
    if(CorrectAnswer.equals(request.getParameter("Answer")))
            
    {
        
    Count++;
            
        %>
        
    <input type="hidden" name="Count" value="<%=Count+1%>" />
        
        <%       
      
    }
        
    else
        
    {
        
        %>
        
        
        <%
    Count = Count+0;
            
        %>
        
    <input type="hidden" name="Count" value="<%=Count%>" />
       
       <% 
        
    }
       
       %> 
    
    </td>
        
    </tr>
    
    <tr>
       
    <td align="center" colspan="2" style="font-family: Cambria; color: white; font-size: 24px">
        
    <a href="Novice.jsp?CorrectAnswer=<%=CorrectAnswer%>&Counter=<%=Counter+1%>&Count=<%=Count%>"><input type="button" name="NextQuestion" value="Next Question" class="Submit" /></a>
        
    </td>
        
    </tr>
    
    </table>
    
    </form>
    
    <%
    
    }
    
    %>
    
</body>

</html>

WELL THATS ALL I HAVE TO GIVE! So when i answer the question the address bar shows the count parameter but the value stays 0 and does not increment. I also tried to put the following like:

if(Answer.equals(CorrectAnswer))

{
   Count++;

}

But unfortunately it gives me a NULLPOINTEREXCEPTION which i HATE ALOT.

All help appreciated :-)

help needed! all feedback greatly appreciated :-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.