Upload OnlineExam.java
#1
by gaurang671 - opened
- OnlineExam.java +98 -0
OnlineExam.java
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import com.sun.net.httpserver.HttpServer;
|
| 2 |
+
import com.sun.net.httpserver.HttpHandler;
|
| 3 |
+
import com.sun.net.httpserver.HttpExchange;
|
| 4 |
+
import java.io.IOException;
|
| 5 |
+
import java.io.OutputStream;
|
| 6 |
+
import java.net.InetSocketAddress;
|
| 7 |
+
|
| 8 |
+
public class OnlineExam {
|
| 9 |
+
public static void main(String[] args) throws Exception {
|
| 10 |
+
|
| 11 |
+
HttpServer server = HttpServer.create(new InetSocketAddress(7860), 0);
|
| 12 |
+
|
| 13 |
+
server.createContext("/", new MyHandler());
|
| 14 |
+
server.setExecutor(null);
|
| 15 |
+
server.start();
|
| 16 |
+
|
| 17 |
+
System.out.println("Server started at http://localhost:7860");
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
static class MyHandler implements HttpHandler {
|
| 21 |
+
public void handle(HttpExchange t) throws IOException {
|
| 22 |
+
|
| 23 |
+
String response =
|
| 24 |
+
"<html>" +
|
| 25 |
+
"<body>" +
|
| 26 |
+
"<h1>Online Exam System</h1>" +
|
| 27 |
+
|
| 28 |
+
"<form>" +
|
| 29 |
+
|
| 30 |
+
"<h3>Q1. What is the capital of India?</h3>" +
|
| 31 |
+
"<input type='radio' name='q1'> Mumbai<br>" +
|
| 32 |
+
"<input type='radio' name='q1'> Delhi<br>" +
|
| 33 |
+
"<input type='radio' name='q1'> Kolkata<br><br>" +
|
| 34 |
+
|
| 35 |
+
"<h3>Q2. 2 + 2 = ?</h3>" +
|
| 36 |
+
"<input type='radio' name='q2'> 3<br>" +
|
| 37 |
+
"<input type='radio' name='q2'> 4<br>" +
|
| 38 |
+
"<input type='radio' name='q2'> 5<br><br>" +
|
| 39 |
+
|
| 40 |
+
"<h3>Q3. Which language is used for AI?</h3>" +
|
| 41 |
+
"<input type='radio' name='q3'> Java<br>" +
|
| 42 |
+
"<input type='radio' name='q3'> Python<br>" +
|
| 43 |
+
"<input type='radio' name='q3'> C<br><br>" +
|
| 44 |
+
|
| 45 |
+
"<h3>Q4. What is the national animal of India?</h3>" +
|
| 46 |
+
"<input type='radio' name='q4'> Lion<br>" +
|
| 47 |
+
"<input type='radio' name='q4'> Tiger<br>" +
|
| 48 |
+
"<input type='radio' name='q4'> Elephant<br><br>" +
|
| 49 |
+
|
| 50 |
+
"<h3>Q5. Which is the largest planet?</h3>" +
|
| 51 |
+
"<input type='radio' name='q5'> Earth<br>" +
|
| 52 |
+
"<input type='radio' name='q5'> Jupiter<br>" +
|
| 53 |
+
"<input type='radio' name='q5'> Mars<br><br>" +
|
| 54 |
+
|
| 55 |
+
"<button type='submit'>Submit Exam</button>" +
|
| 56 |
+
|
| 57 |
+
"</form>" +
|
| 58 |
+
|
| 59 |
+
"<p>Result: Demo Page (Logic not added yet)</p>" +
|
| 60 |
+
|
| 61 |
+
"</body>" +
|
| 62 |
+
"</html>";
|
| 63 |
+
|
| 64 |
+
t.sendResponseHeaders(200, response.getBytes().length);
|
| 65 |
+
OutputStream os = t.getResponseBody();
|
| 66 |
+
os.write(response.getBytes());
|
| 67 |
+
os.close();
|
| 68 |
+
}
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
public static void main(String[] args) {
|
| 72 |
+
|
| 73 |
+
int score = 0;
|
| 74 |
+
|
| 75 |
+
System.out.println("===== ONLINE EXAM SYSTEM =====");
|
| 76 |
+
|
| 77 |
+
// Q1
|
| 78 |
+
System.out.println("Q1. Capital of India?");
|
| 79 |
+
int a1 = 2; // predefined answer (Delhi)
|
| 80 |
+
if (a1 == 2) score++;
|
| 81 |
+
|
| 82 |
+
// Q2
|
| 83 |
+
System.out.println("Q2. National animal of India?");
|
| 84 |
+
int a2 = 2; // Tiger
|
| 85 |
+
if (a2 == 2) score++;
|
| 86 |
+
|
| 87 |
+
// Q3
|
| 88 |
+
System.out.println("Q3. 2 + 2 = ?");
|
| 89 |
+
int a3 = 2; // 4
|
| 90 |
+
if (a3 == 2) score++;
|
| 91 |
+
|
| 92 |
+
System.out.println("\nRESULT");
|
| 93 |
+
System.out.println("Score: " + score + "/3");
|
| 94 |
+
|
| 95 |
+
if (score == 3) System.out.println("Excellent");
|
| 96 |
+
else System.out.println("Try Again");
|
| 97 |
+
}
|
| 98 |
+
}
|