Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

frustrated...Please provide a complete code that works perfectly please... I have asked three times, and the codes they gave me is not working correctly.(one of

frustrated...Please provide a complete code that works perfectly please... I have asked three times, and the codes they gave me is not working correctly.(one of the "Experts" is not even answering my question,) I am so stressed right now.. can anyone help me out??? Make sure the code that can have the fill in blank question and the multiple choices problems. And users are able to answer them. And the user will get a score at the end to show as the percentage.

image text in transcribedimage text in transcribed

heres the code I have so far:

package hw4;

import java.util.ArrayList;

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 = quString + " "+questionChoices.get(i);

}

return quString;

}

}

package hw4;

import java.util.ArrayList; class Question {

private String question;

private String answer;

public Question() {

question = "Blank";

answer= "Blank";

}

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 hw4;

import java.util.ArrayList;

public class FiBQuestion extends Question {

public FiBQuestion(String question, String correctAnswerFIB) {

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 hw4;

import java.util.ArrayList;

import java.util.Scanner;

class Quiz {

ArrayList qArrayList;

ArrayList userResponses;

int grade;

public Quiz(ArrayList qArrayList) {

this.qArrayList = qArrayList;

this.userResponses = new ArrayList();

}

public void allowQuiz() {

//display question

Scanner in =new Scanner(System.in);

for(int i = 0; i

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

System.out.println(" Enter the answer");

userResponses.add(in.nextLine());

}

//check

for (int i = 0; i

for(int j = 0; j

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

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

grade += 1;

System.out.println(grade);

}

}

}

}

}

package hw4;

import java.util.ArrayList;

public class Main {

public static void main(String[] args) {

ArrayList questions=new ArrayList();

//MCQuestion mcQuestion=new MCQuestion(); String s1 = "_____is the largest freshwater lake in the world"; String s2 = "_____is someone who shoes horses."; String s3 = "_____is another word for lexicon."; String s4 = "The seventh planet from the sun is_____."; String s5 = "A _____ is Biggest planet in solar system";

FiBQuestion fiBQuestion = new FiBQuestion(s1, "Lake Superior" ); FiBQuestion fiBQuestion1 = new FiBQuestion(s2, "A farrier"); FiBQuestion fiBQuestion2 = new FiBQuestion(s3, "Dictionary"); FiBQuestion fiBQuestion3 = new FiBQuestion(s4, "Uranus"); FiBQuestion fiBQuestion4 = new FiBQuestion(s5,"Jupitor");

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

MCQuestion mcQuestion=new MCQuestion(); mcQuestion.setQuestion("Which of the following is not one of the four pillars of Object Oriented Programming?"); questions.add(mcQuestion); mcQuestion.addChoices("a. Abstraction", false);

mcQuestion.addChoices("b. Provisioning", true);

mcQuestion.addChoices("c. Encapsulation", false);

mcQuestion.addChoices("d. Polymorphism", false);

mcQuestion=new MCQuestion(); mcQuestion.setQuestion("What is the derivative of ln(x)?"); questions.add(mcQuestion); mcQuestion.addChoices("a. e^x", false);

mcQuestion.addChoices("b. 1/x", true);

mcQuestion.addChoices("c. x^2", false);

mcQuestion.addChoices("d. ln(x)", false);

mcQuestion=new MCQuestion(); mcQuestion.setQuestion("What is the output of [ln(1) + e^0 - (sin^2(theta) + cos^2(theta))]?"); questions.add(mcQuestion); mcQuestion.addChoices("a. 0.9", false);

mcQuestion.addChoices("b. 34", false);

mcQuestion.addChoices("c. 0", true);

mcQuestion.addChoices("d. 2", false);

mcQuestion=new MCQuestion(); mcQuestion.setQuestion("What is the integral of sec(x)?"); questions.add(mcQuestion); mcQuestion.addChoices("a. ln|csc(x) + cot(x) | + C", false);

mcQuestion.addChoices("b. 1 / (sec(x) + tan (x)) + C", false);

mcQuestion.addChoices("c. sec(x) / (csc(x) + cot(x))", false);

mcQuestion.addChoices("d. ln|sec(x) + tan(x)| + C", true);

mcQuestion=new MCQuestion();

mcQuestion.setQuestion("Which language has the most population of speaking?"); questions.add(mcQuestion); mcQuestion.addChoices("a. English ", false);

mcQuestion.addChoices("b. Chinese", true);

mcQuestion.addChoices("c. Japanese", false);

mcQuestion.addChoices("d. Spanish", false);

Quiz quiz=new Quiz(questions); 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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions