<% String message = (String) session.getAttribute("message"), good = (String) session.getAttribute("good"), total = (String) session.getAttribute("total"), n1 = (String) session.getAttribute("n1"), n2 = (String) session.getAttribute("n2"), // state is above answer = request.getParameter("answer"), reset = request.getParameter("reset"); // input if (message == null || reset != null) { good = "0"; total = "0"; n1 = "" + (int) ((Math.random() * 100) - 50); n2 = "" + (int) ((Math.random() * 100) - 50); message = "(" + good + "/" + total + ") What is " + n1 + " + " + n2 + "? Type your answer here: "; } else { int a = Integer.parseInt(n1) + Integer.parseInt(n2); try { if (a == Integer.parseInt(answer)) { good = "" + (Integer.parseInt(good) + 1); } } catch (Exception e) { } total = "" + (Integer.parseInt(total) + 1); n1 = "" + (int) ((Math.random() * 100) - 50); n2 = "" + (int) ((Math.random() * 100) - 50); message = "(" + good + "/" + total + ") What is " + n1 + " + " + n2 + "? Type your answer here: "; } session.setAttribute("message", message); session.setAttribute("good", good); session.setAttribute("total", total); session.setAttribute("n1", n1); session.setAttribute("n2", n2); %> Lab 04/13 Servlet
<%=message%>

Type to move on.


Type to reset your game.