//******************************************************************** // Question.java Author: Lewis/Loftus // // Solution to Programming Project 6.10 & 6.11 // //******************************************************************** public class Question { private String question, answer; private int complexityLevel; //----------------------------------------------------------------- // Sets up the question with a default complexity. //----------------------------------------------------------------- public Question (String query, String result) { question = query; answer = result; complexityLevel = 1; } //----------------------------------------------------------------- // Sets the complexity level for this question. //----------------------------------------------------------------- public void setComplexity (int level) { complexityLevel = level; } //----------------------------------------------------------------- // Returns the complexity level for this question. //----------------------------------------------------------------- public int getComplexity() { return complexityLevel; } //----------------------------------------------------------------- // Returns the question. //----------------------------------------------------------------- public String getQuestion() { return question; } //----------------------------------------------------------------- // Returns the answer to this question. //----------------------------------------------------------------- public String getAnswer() { return answer; } //----------------------------------------------------------------- // Returns true if the candidate answer matches the answer. //----------------------------------------------------------------- public boolean answerCorrect (String candidateAnswer) { return answer.equals(candidateAnswer); } //----------------------------------------------------------------- // Returns this question (and its answer) as a string. //----------------------------------------------------------------- public String toString() { return question + "\n" + answer; } } //******************************************************************** // Quiz.java Author: Erik Rogers // // Allows for up to 25 questions // adds questions/gives quiz/accepts answer/stores results // does not use the Quesitons class. Couldn't figure out how to implement it // Question blah = new Question? //******************************************************************** import java.util.List; import java.util.ArrayList; import java.util.Iterator; import java.util.ListIterator; import java.util.Collections; import java.util.Random; import java.util.Scanner; public class Quiz{ int capacity = 25; Scanner userinput = new Scanner(System.in); List questionlist = new ArrayList(capacity); List answerlist = new ArrayList(capacity); List correctanswerslist = new ArrayList(capacity); public void answerQuestions(){ String a; for (int i = 0; i < 25; i++){ System.out.print(questionlist.get(i)); System.out.print("Answer #" + i); a = userinput.next(); answerlist.add(a);} } public void addQuestion(){ String q; for (int i = 0; i < 25; i++){ System.out.print("Question #" + i); q = userinput.next(); questionlist.add(q);} } public void addAnswer(){ String ca; for (int i = 0; i < 25; i++){ System.out.print("Correct Answer #" + i); ca = userinput.next(); correctanswerslist.add(ca);} } public void getAnswersAndQuestions(){ for (int i = 0; i < 25; i++) { System.out.print(questionlist.get(i)+": "+answerlist.get(i));} }}