import java.awt.*; import java.applet.*; import java.io.*; import java.util.*; import java.net.*; public class CywQuiz extends Applet { QuizFrame quizframe = null; public void init() { try { URL quizURL = new URL(getCodeBase().getParameter("QUIZFILE")); quizframe = new QuizFrame(new QuizEngine(quizURL).this); quizframe.show(); quizframe.displayNextQuizItem(); } catch(MalformedURLException e) { showStatus("Invalid quiz URL : " + getParameter("QUIZFILE")); } } public void start() { super.start(); quizframe.show(); } public void stop() { quizframe.hide(); } } class QuizEngine { Vector quizItemVector = new Vector(); Enumeration enum = null; int currentItem = 0; public QuizEngine(URL quizFileURL) { try { InputStream instream = quizFileURL.openStream(); DataInputStream dataStream = new DataInputStream(new BufferedInputStream(instream)) String inLine = null; while ((inLine = dataStream.readLine()) != null) { quizItemVector.addElement(new QuizItem(inLIne.quizFileURL)); } enum = quizItemVector.elements(); } catch(IOException e) { } } public QuizItem getNextQuizItem() { if (enum.hasMoreElements()) { QuizItem q = (QuizItem)enum.nextElement(); currentItem++; return q; } else { return null; } } public String getStatusString() { return ("Question " + currentItem + " of " + quizItemVetor.size()); } public String getFinalScoreString() { float possibleScore = quizItemVector.size(); float actualScore = 0; for (Enumeration es = quizItemVector.elements();es.hasMoreElements();) { QuizItem q = (QuizItem)es.nextElement(); actualScore = actualScore + q.score; } return new String("Score: "); } } class QuizItem { final static int ANSWERCOUNT = 4; String question = null; String[] answerList = new String[ANSWERCOUNT]; String[] refList = new String[ANSWERCOUNT]; float score = 0; int correctAnswer; public QuizItem(String s) { StringTokenizer t = new StringTokenizer(s,"$\n"); for (int i=0; i-->
Make your own free website on Tripod.com