/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ File: QuestionList.java Date: 4/5/2006 Author: mr. Hanley Purpose: Read in a list of questions from disk 11/9/2010:Updated so the Questions can be multiple lines @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ import java.io.*; //BufferedReader, FileReader import java.util.ArrayList; public class QuestionList { public QuestionList() { } /** * public ArrayList loadQuiz(String fileName) * * @param fileName String * @return ArrayList */ public ArrayList loadQuiz(String fileName) { ArrayList temp = new ArrayList(); BufferedReader br = null; try { br = new BufferedReader(new FileReader(fileName)); //Read the first ? or find and end of file String tempRead = ""; tempRead = br.readLine(); //Loop as long as there are more while (tempRead != null) { Question q = new Question(); //Read in the question text q.qText = new ArrayList(); while (true) { String tempLine = br.readLine(); //read a line //Is this the delimiter? if (tempLine == null || tempLine.equals("+")) { break; } //This must be a line of the question q.qText.add(tempLine); //add the text to the end //q.qText = br.readLine(); } String tempAns = br.readLine(); int i=0; //As long as we haven't hit the -... while (!tempAns.equals("-")) { q.ans[i] = tempAns; i++; tempAns = br.readLine(); } //Now we've got the ?'s //Get the correct answer q.correctAns = Byte.parseByte(br.readLine()); //Put this question in the arrayList temp.add(q); //Skip the ? tempRead = br.readLine(); } //Close the stream br.close(); } catch (FileNotFoundException e) { System.out.println(e); } catch (IOException e) { } return temp; } }