File size: 3,460 Bytes
9b86624
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpExchange;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;

public class OnlineExam {
    public static void main(String[] args) throws Exception {

        HttpServer server = HttpServer.create(new InetSocketAddress(7860), 0);

        server.createContext("/", new MyHandler());
        server.setExecutor(null);
        server.start();

        System.out.println("Server started at http://localhost:7860");
    }

    static class MyHandler implements HttpHandler {
        public void handle(HttpExchange t) throws IOException {

            String response =
                    "<html>" +
                    "<body>" +
                    "<h1>Online Exam System</h1>" +

                    "<form>" +

                    "<h3>Q1. What is the capital of India?</h3>" +
                    "<input type='radio' name='q1'> Mumbai<br>" +
                    "<input type='radio' name='q1'> Delhi<br>" +
                    "<input type='radio' name='q1'> Kolkata<br><br>" +

                    "<h3>Q2. 2 + 2 = ?</h3>" +
                    "<input type='radio' name='q2'> 3<br>" +
                    "<input type='radio' name='q2'> 4<br>" +
                    "<input type='radio' name='q2'> 5<br><br>" +

                    "<h3>Q3. Which language is used for AI?</h3>" +
                    "<input type='radio' name='q3'> Java<br>" +
                    "<input type='radio' name='q3'> Python<br>" +
                    "<input type='radio' name='q3'> C<br><br>" +

                    "<h3>Q4. What is the national animal of India?</h3>" +
                    "<input type='radio' name='q4'> Lion<br>" +
                    "<input type='radio' name='q4'> Tiger<br>" +
                    "<input type='radio' name='q4'> Elephant<br><br>" +

                    "<h3>Q5. Which is the largest planet?</h3>" +
                    "<input type='radio' name='q5'> Earth<br>" +
                    "<input type='radio' name='q5'> Jupiter<br>" +
                    "<input type='radio' name='q5'> Mars<br><br>" +

                    "<button type='submit'>Submit Exam</button>" +

                    "</form>" +

                    "<p>Result: Demo Page (Logic not added yet)</p>" +

                    "</body>" +
                    "</html>";

            t.sendResponseHeaders(200, response.getBytes().length);
            OutputStream os = t.getResponseBody();
            os.write(response.getBytes());
            os.close();
        }
    }
}
    public static void main(String[] args) {

        int score = 0;

        System.out.println("===== ONLINE EXAM SYSTEM =====");

        // Q1
        System.out.println("Q1. Capital of India?");
        int a1 = 2; // predefined answer (Delhi)
        if (a1 == 2) score++;

        // Q2
        System.out.println("Q2. National animal of India?");
        int a2 = 2; // Tiger
        if (a2 == 2) score++;

        // Q3
        System.out.println("Q3. 2 + 2 = ?");
        int a3 = 2; // 4
        if (a3 == 2) score++;

        System.out.println("\nRESULT");
        System.out.println("Score: " + score + "/3");

        if (score == 3) System.out.println("Excellent");
        else System.out.println("Try Again");
    }
}