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 = "" + "
" + "Result: Demo Page (Logic not added yet)
" + "" + ""; 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"); } }