<%@ page import ="java.util.*" %> <% String url = "http://www.cs.indiana.edu/classes/a202-dger/fall2005/not" + "es/flagquiz/images/"; String message = (String) session.getAttribute("message"), key = (String) session.getAttribute("key"), good = (String) session.getAttribute("good"), total = (String) session.getAttribute("total"), b = (String) session.getAttribute("questions"), input = "", answer = request.getParameter("answer"); if (message == null) { message = "Welcome to the game, are you ready?"; String[] flags = { "Australia", "China", "Russia", "Spain", "Brazil", "Italy", "South Africa", "United States" }; for (int i = 0; i < 100; i++) { int index = (int) (Math.random() * flags.length); int other = (int) (Math.random() * flags.length); String temp = flags[index]; flags[index] = flags[other]; flags[other] = temp; } b = ""; for (int i = 0; i < flags.length; i++) { b += flags[i]; if (i < flags.length - 1) b += ","; } good = "0"; total = "0"; } else { // grade first, so you can ask a new question if (answer != null) { if (key.equals(answer)) { good = (Integer.parseInt(good) + 1) + ""; } total = (Integer.parseInt(total) + 1) + ""; } // now ask a new question StringTokenizer st = new StringTokenizer(b, ","); if (st.hasMoreTokens()) { key = st.nextToken(); b = ""; while (st.hasMoreTokens()) { b += st.nextToken(); if (st.hasMoreTokens()) b += ","; } input = "\n " + " is the flag of

"; message = "Score so far: " + good + " out of " + total ; } else { // running out of questions } } session.setAttribute("message", message); session.setAttribute("questions", b); session.setAttribute("key", key); session.setAttribute("good", good); session.setAttribute("total", total); %>

<%=message%>

<%=input%> Press when ready.