Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this project, you will: -create a quiz of up to 25 questions and answers, -give the quiz, and -output how many correct and incorrect

For this project, you will:

-create a quiz of up to 25 questions and answers,

-give the quiz, and

-output how many correct and incorrect answers were given.

You will use an array of 25 Question objects created from the class Question of the Chapter 7 source files. The program should utilize:

class Question (provided at bottom)

Class Question contains:

-constructor for class Question that accepts 2 strings for the question and the answer and an integer which is not used by this program (complexity not used)

-getQuestion method that returns the question part of the Question object

-answerCorrect method that accepts a string for the potential answer and returns true if the string matches the correct answer in the Question object.

class Quiz

Class Quiz contains:

-declarations of an array to hold Questions (Question objects from Class Question), an int to count correct answers, an int to count incorrect answers

-constructor that instantiates an initially empty array for 25 Questions

-add method that accepts 2 strings (question and answer) passed as parameters, instantiates a new Question object and inserts the Question object into the next element of the array

-giveQuiz method that loops through the array and outputs the question, uses scanner to read an answer from the user, and invokes answerCorrect to determine whether the answer was correct and increments the appropriate count.

-getNumCorrect method that returns the number answered correctly

-getNumIncorrect method that returns the number answered incorrectly

class QuizTime

Contains the main method that:

-instantiates a Quiz object

-populates the quiz by invoking the add method 25 times, passing a question and answer string each time.

-invokes the giveQuiz method

-outputs the number correct and the number incorrect using methods getNumCorrect and getNumIncorrect

Save the files as QuizTime_XXX.java and Quiz_XXX.java, substituting your initials for XXX. No need to change the Question class so no need to upload Question.java.

Question.java

//******************************************************************** // Question.java Author: Lewis/Loftus // // Represents a question (and its answer). //********************************************************************

public class Question implements Complexity { private String question, answer; private int complexityLevel;

//----------------------------------------------------------------- // Constructor: 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 + " " + answer; } }

Please inlcude documentation so I can learn and undrstand the code better, thank you!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

More Books

Students also viewed these Databases questions

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago