The website has been updated, checkout below websites.

https://codingvariable.com/

Thursday, 5 January 2017

Create A Multiple Choice Quizz Using Html & Servlet


Mcq.html


 <html>
    <head>
        <title>Java MCQ</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <form name="frm" method="get" action="mcq">
        <h1 align="center">Multiple Choice Question(MCQ)</h1>
        <br>
        Q1.Which of these keyword must be used to inherit a class?<br>
        <input type="radio" name="a" value="super">super<br>
        <input type="radio" name="a" value="this">this<br>
        <input type="radio" name="a" value="extent">extent<br>
        <input type="radio" name="a" value="extends">extends<br>
        <br>
        Q2.Which of the following is a legal identifier in java ?<br>
        <input type="radio" name="b" value="2variable">2variable<br>
        <input type="radio" name="b" value="#myvar">#myvar<br>
        <input type="radio" name="b" value="+@$var">+@$var<br>
        <input type="radio" name="b" value="$_myvar">$_myvar<br>
        <br>
        Q3.Which of these is NOT valid keyword or reserved word in Java ?<br>
        <input type="radio" name="c" value="default">default<br>
        <input type="radio" name="c" value="null">null<br>
        <input type="radio" name="c" value="String">String<br>
        <input type="radio" name="c" value="volatile">volatile<br>
        <br>
        Q.4 A special method that is used to initialize a class object ?<br>
        <input type="radio" name="d" value="abstract method">abstract method<br>
        <input type="radio" name="d" value="static method">static method<br>
        <input type="radio" name="d" value="Constructor">Constructor<br>
        <input type="radio" name="d" value="overloaded method">overloaded method<br>
        <br>
        <input type="submit" value="submit">
        </form>
    </body>
</html>


Mcq.java


import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class mcq extends HttpServlet {

   
 
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        
        PrintWriter out = response.getWriter();
        String q1=request.getParameter("a");
        String q2=request.getParameter("b");
        String q3=request.getParameter("c");
        String q4=request.getParameter("d");
        
        if(q1.equals("extends")){
            out.println("correct");
        }
        else{
            out.println("Incorrect");
        }
        
        if(q2.equals("$_myvar")){
            out.println("correct");
        }
        else{
            out.println("Incorrect");
        }
        
        if(q3.equals("String")){
            out.println("correct");
        }
        else{
            out.println("Incorrect");
        }
        
        if(q4.equals("Constructor")){
            out.println("correct");
        }
        else{
            out.println("Incorrect");
        }
    }   
       
}



Output


Java MCQ

Multiple Choice Question(MCQ)


Q1.Which of these keyword must be used to inherit a class?
super
this
extent
extends

Q2.Which of the following is a legal identifier in java ?
2variable
#myvar
+@$var
$_myvar

Q3.Which of these is NOT valid keyword or reserved word in Java ?
default
null
String
volatile

Q.4 A special method that is used to initialize a class object ?
abstract method
static method
Constructor
overloaded method

No comments:

Post a Comment