import java.io.*; import java.text.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; public class SecondTestA extends HttpServlet { public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); String title = "Test Result"; int totalQuestion = 10; int correct = 0; String answer = null; String[] correctAnswer = new String[totalQuestion]; PrintWriter out = response.getWriter(); correctAnswer[0] = "True"; correctAnswer[1] = "Technology"; correctAnswer[2] = "all of the above"; correctAnswer[3] = "apathy"; correctAnswer[4] = "Uncertainty"; correctAnswer[5] = "financial trouble"; correctAnswer[6] = "Selection"; correctAnswer[7] = "all of the above"; correctAnswer[8] = "360 degree feedback"; correctAnswer[9] = "False"; out.println(""); out.println(""); out.println("" + title + ""); out.println(""); out.println(""); for(int i=0; i < totalQuestion; i++) { answer = request.getParameter("question" + i); out.println("
"); int j = i; j++; if (answer != null) { if (answer.equals(correctAnswer[i])) { out.println("Your answer for number " + j + " is correct " + answer + "."); correct++; } else out.println("Your answer for number " + j + " is incorrect, you answered " + answer + " the correct answer is " + correctAnswer[i] + "."); } else out.println("You did not answer question number " + j + " the correct answer is " + correctAnswer[i] + "."); } out.println("
"); out.println("
"); float f = (float)correct/totalQuestion; f *= 100.0; int per = (int) f; out.println("Your grade is " + per + "% "); out.println(""); out.println(""); } public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { } }