Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi please read my question !! and please give me a thorough explanation please! someone answered this question, but I think the main class is

Hi please read my question !! and please give me a thorough explanation please!

image text in transcribed

image text in transcribed

someone answered this question, but I think the main class is kind of off. I don't know how to make a user menu for user to take the quiz and also how to add the questions I want to ask and the correct answers to the questions. (Also how to store the user response) ....

I was trying this in the Main class, but I do not know whether this is the correct start?

:

public static void main(String[] args) { Scanner scanner = new Scanner(System.in); ArrayList questions=new ArrayList(); ArrayList answers = new ArrayList(); FiBQuestion fiBQuestion = new FiBQuestion("_____is the largest freshwater lake in the world"); FiBQuestion fiBQuestion1 = new FiBQuestion("_____is someone who shoes horses."); FiBQuestion fiBQuestion2 = new FiBQuestion("_____is another word for lexicon."); FiBQuestion fiBQuestion3 = new FiBQuestion("The seventh planet from the sun is_____."); FiBQuestion fiBQuestion4 = new FiBQuestion("A _____ is a falchion.");

questions.add(fiBQuestion); questions.add(fiBQuestion1); questions.add(fiBQuestion2); questions.add(fiBQuestion3); questions.add(fiBQuestion4);

questions.add(new MCQuestion());

I am just lost right now, can anyone please provide me with a better Main class, where a menu will prompt out and ask the user to take the quiz and also the quiz will work properly,(you can just provide me with random questions and answers you made up) ! Appreciate for your help.

And below is the code that someone else helped me out, I think the other classes work fine, just the main class.....

The assignment is the pictures above! Thank you very much!!

/////

package quiz;

public class Question {

private String question;

private String answer;

public Question() {

question=null;

answer=null;

}

public boolean isAnswerCorrect(String answer) {

if (this.answer.equalsIgnoreCase(answer)) {

return true;

}

return false;

}

public Question(String question, String answer) {

this.question = question;

this.answer = answer;

}

public String getQuestion() {

return question;

}

public void setQuestion(String question) {

this.question = question;

}

public String getAnswer() {

return answer;

}

public void setAnswer(String answer) {

this.answer = answer;

}

@Override

public String toString() {

return question;

}

}

//////////

package quiz;

import java.util.ArrayList;

public class MCQuestion extends Question{

ArrayList questionChoices;

String answer;

public MCQuestion() {

questionChoices=new ArrayList();

}

public void addChoices(String possibleAnswer,boolean isAnswer) {

questionChoices.add(possibleAnswer);

if (isAnswer) {

answer=""+questionChoices.size();

}

}

public void setQuestion() {

super.setQuestion(toString());

super.setAnswer(answer);

}

@Override

public String toString() {

String quString=getQuestion();

for (int i = 0; i

quString+=" "+questionChoices.get(i);

}

return quString;

}

}

////////

package quiz;

public class FiBQuestion extends Question {

public FiBQuestion(String question) {

super(parseQuestion(question),

question.substring(question.indexOf('_')+1,question.lastIndexOf('_')));

}

private static String parseQuestion(String question){

return question.substring(0,question.indexOf('_'))

+"------------"+question.substring(question.lastIndexOf('_'));

}

@Override

public String toString() {

// TODO Auto-generated method stub

return getQuestion();

}

}

////////

package quiz;

import java.util.ArrayList;

public class Quiz {

ArrayList qArrayList;

ArrayList userResponses;

int grade;

public Quiz(ArrayList qArrayList, ArrayList userResponses) {

this.qArrayList = qArrayList;

this.userResponses = userResponses;

}

public void allowQuiz() {

for (int i = 0; i

System.out.println("Q. " + (i + 1) + " " + qArrayList.get(i));

System.out.println(" User Answer:" + userResponses.get(i) + " ");

System.out.println(qArrayList.get(i)+" "+userResponses.get(i));

if (qArrayList.get(i).isAnswerCorrect(userResponses.get(i))) {

grade += 1;

}

}

System.out.println("Score is " + (grade*100)/10+"%");

}

}

/////////////

package quiz;

import java.util.ArrayList;

public class MainClass {

public static void main(String[] args) {

ArrayList questions=new ArrayList();

//MCQuestion mcQuestion=new MCQuestion();

for (int i = 0; i

FiBQuestion fiBQuestion=new FiBQuestion("How _are_ you");

questions.add(fiBQuestion);

}

for (int i = 5; i

MCQuestion mcQuestion=new MCQuestion();

mcQuestion.addChoices("a. is answer", false);

mcQuestion.addChoices("b. is answer", true);

mcQuestion.addChoices("c. is answer", false);

mcQuestion.addChoices("d. is answer", false);

mcQuestion.setQuestion();

questions.add(mcQuestion);

}

ArrayList userResponses=new ArrayList();

for (int i = 0; i

userResponses.add("are");

}

for (int i = 5; i

userResponses.add("2");

}

Quiz quiz=new Quiz(questions, userResponses);

quiz.allowQuiz();

}

General Description: For this assignment you will be writing a program that can allow a user to take a Quiz. This assignment will utilize inheritance to design the classes Please use hw4 for the package name The Question Class: .A Question contains the text of the question and the correct answer to the question. NOTE: Answers can be stored as Strings o . A Question should have a default constructor to initialize the data fields to some default value .A Question should also have a constructor which takes as input the text of the question and the answer to a question .You may provide any other constructors as necessary. .A Question has the following behaviors. o Set and get the text of a question o Set and get the text of an answer to a question o Grade a question given a response to a question. This should take the user's answer as a parameter and return true or false depending on if the user got the question correct or not. o Implement a toString) method to print the question (not the answer) The MCQuestion Class: This class is a subclass of the Question class and will handie multiple choice questions with only one possible answer. .An MCQuestion should have an ArrayList where each element of the ArrayList is a possible choice for the question .An MCQuestion should have a constructor which initializes an empty ArrayList, as well as the question text. The answer will be initialized by one of the methods listed below. . An MCQuestion has the following behaviors o Add a choice to the list of choices. This method should have two parameters, the text of a possible answer as well as a boolean value. If the boolean value is true, this is the answer to t question and the correct letter (a, b, c, d, etc) should be assigned as the answer. If the value is false, this is not the correct answer to the question. o NOTE: The index of the ArrayList corresponds to the letter of the possible answer. Example: index 0 is "a", index 1 is "b", and so on. Override the toString0 method to show the question, and the list of possible answers (with corresponding letter before each answer) The FiBQuestion Class: . This class is a subclass of the Question class and will handle fill in the blank type questions A fill in the blank question has a constructor which takes ONLY the question in the following format: "Java is a_statically typed_ language o This constructor should take the question and parse out the answer (which is denoted using underscores.) o When the question is displayed it should be shown as "Java is a anguage .An FiBQuestion has the following behaviors o a private method to parse out the answer from the given

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

Medical Image Databases

Authors: Stephen T.C. Wong

1st Edition

1461375398, 978-1461375395

More Books

Students also viewed these Databases questions