Question
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.
heres the code I have so far:
package hw4;
import java.util.ArrayList;
class MCQuestion extends Question{
ArrayList
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
ArrayList
int grade;
public Quiz(ArrayList
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 //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(); }}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started