Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using classes Question.java, MultipleChocie.java, and FreeResponse.java you are going to write a class called Quiz.java. The quiz class has one instance variable: an ArrayList of

Using classes Question.java, MultipleChocie.java, and FreeResponse.java you are going to write a class called Quiz.java. The quiz class has one instance variable: an ArrayList of Question objects. Your class will have one constructor and one method called takeQuiz.

Constructor: The constructor will take no parameters, and will interact with the user, inputting the questions. This will be a complex constructor that does much more than just assign variables.

Enter the text of the question:

What color is the sky?

Is your question an MC? Y or N

Y

How many choices are there?

4

Enter choice text:

red

Is it correct? Y or N

N

Enter choice text:

green

Is it correct? Y or N

N

Enter choice text:

blue

Is it correct? Y or N

Y

Enter choice text:

yellow

Is it correct? Y or N

N

Do you want to input another question? Y or N

Y

Enter the text of the question:

What is 2+2?

Is your question an MC? Y or N

N

Enter the correct answer to your question:

4

Do you want to input another question? Y or N

N

Your quiz is built.

One thing that youll need to know: in order to read input that is more than one word you will need to do in.next() + in.nextLine() in order to properly read the entire line.

TakeQuiz: this method allows the user to take their quiz and gives them a percentage score. If the question is a Multiple Choice question, the user will only enter one letter as the answer, so you must just use in.next() to get the answer. If the question is a FreeResponse the user could enter multiple words so you must use in.next() + in.nextLine(); to read in the answer.

1. What color is the sky?

A. red

B. green

C. blue

D. yellow

Answer: C

Correct!

2. What is 2+2?

Answer: 2

Wrong!

You scored: 50.0 %

Main: Main should instantiate the class, and call takeQuiz outputting the returned value.

/* Free Response * AP CS A */ import java.util.*; public class FreeResponse extends Question{ private String correctAns; public FreeResponse(String text, String correct) { } public boolean checkAnswer(String answ) { } }

/* MultipleChoice * AP CS A */ import java.util.*; public class MultipleChoice extends Question{ private String correctAns; private ArrayList choices; public MultipleChoice(String text){ } //add choice to the ArrayList choices and set answer public void addChoice(String choice, boolean correct){ } public boolean checkAnswer(String choice) { } public void display(){ } } }

/* Question.java * AP CS A */ public class Question { private String text; public static int numQuestions = 0; //constructor with parameters public Question(String text){ this.text = text; Question.numQuestions++; } //display the question public void display(){ System.out.print(Question.numQuestions + ". "); System.out.println(text); } public static void resetQuestionNum(){ numQuestions = 0; } }

/* AP CS * Quiz Program */ import java.util.*; public class Quiz { private ArrayList questions; public Quiz() { } public double takeQuiz() { //return percentage score } public static void main(String[] args) { Quiz q = new Quiz(); System.out.println("You scored: " + q.takeQuiz()); } }

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

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

2nd Edition

0470624701, 978-0470624708

More Books

Students also viewed these Databases questions

Question

Q3 - Significant Events Impact on Audit Risk components

Answered: 1 week ago