Quiz2 - if (questions[i].answerCorrect(sc.nextLine()))...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
//******************************************************************** // Quiz2.java Author: Lewis/Loftus // // Solution to Programming Project 6.11 // //******************************************************************** / import java.util.Scanner; i public class Quiz2 { private final int MAX_QUESTIONS = 25; private Question[] questions; private int current; private int correct; private int incorrect; public Quiz2() { questions = new Question[MAX_QUESTIONS]; current = 0; correct = incorrect = 0; } public void add(Question newQuestion) { if (current < MAX_QUESTIONS) questions[current++] = newQuestion; } public void giveQuiz() { Scanner sc = new Scanner (System.in); for (int i = 0; i < current; i++) { System.out.println(questions[i].getQuestion());
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: if (questions[i].answerCorrect(sc.nextLine())) correct++; else correct--; } } public void giveQuiz(int minComplexity, int maxComplexity) { Scanner sc = new Scanner (System.in); for (int i = 0; i &lt; current; i++) { int complexity = questions[i].getComplexity(); if (complexity &gt;= minComplexity &amp;&amp; complexity &lt;= maxComplexity) { System.out.println(questions[i].getQuestion()); if (questions[i].answerCorrect(sc.nextLine())) correct++; else correct--; } } if (correct == 0 &amp;&amp; incorrect == 0) System.out.println(&quot;Sorry, no questions fall within the specified complexity range&quot;); } public int getNumCorrect() { return correct; } public int getNumIncorrect() { return incorrect; } }...
View Full Document

Page1 / 2

Quiz2 - if (questions[i].answerCorrect(sc.nextLine()))...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online