Professional Documents
Culture Documents
Sign In
More
.
home / homework help / questions and answers / engineering / computer science / x.hmhad to write a program called
multiplechoice.java ...
Anonymous
0 pts ended
Abaho K.
Stanford U.
Here is my code:
Angela S.
Brown U.
Ethan C.
Columbia U.
Ask a question
Find textbook solutions
}
public void setQuestion(String questionText)
{
this.questionText = questionText;
questionsCreated();
}
public boolean setAnswer(char whichAnswer, String answerText)
{
this.whichAnswer = whichAnswer;
this.answerText = answerText;
if (whichAnswer=='a')
option = true;
answer_a=answerText;
}
if (whichAnswer=='b')
option = true;
answer_b=answerText;
}
if (whichAnswer=='c')
option = true;
answer_c=answerText;
}
if (whichAnswer=='d')
option = true;
answer_d=answerText;
}
if (whichAnswer=='e')
option = true;
answer_e=answerText;
}
else{
option = false;
}
return option;
}
converted by Web2PDFConvert.com
return correctChar;
}
public static boolean grade(MultipleChoice q, char selection)
{
boolean compare_answers;
if(selection == correctChar)
{
compare_answers = true;
}
else
{
compare_answers = false;
}
return compare_answers;
}
public static int questionsCreated()
{
questions++;
return questions;
}
public void setIndex(int i)
{
index = i;
}
public String toString()
{
String newQuestion = index+". "+questionText+"\n "+
"a) "+answer_a+"\n "+
"b) "+answer_b+"\n "+
"c) "+answer_c+"\n "+
"d) "+answer_d+"\n "+
"e) "+answer_e+"\n ";
return newQuestion;
}
}
Then I had to create another program called Quiz.java that contains 5 MultipleChoice
questions and the name of the quiz.
The part that I am stuck on is the method:
public boolean addQuestion(int index, MultipleChoice q)
It says that this method should add a question to the quiz and specify the index of the
question (1-5). If an invalid number is sent (one that is not 1-5), then the method should
return false and not add the question.
BUT I DONT EVEN KNOW WHERE TO START ON THIS METHOD!!!
I should be able to type this in the interactions pane:
q.setAnswer('a', "First Choice");
q.setAnswer('b', "Second Choice");
q.setAnswer('c', "Third Choice");
q.setAnswer('d', "Fourth Choice");
q.setAnswer('e', "Fifth Choice");
q.setQuestion("This is the question.");
example.addQuestion(3, q)
it would add that question to the 3rd index like this:
Quiz 1
1.
b)
c)
d)
e)
2.
a)
b)
c)
d)
e)
3. This is the question.
a) First Choice
converted by Web2PDFConvert.com
b) Second Choice
c) Third Choice
d) Fourth Choice
e) Fifth Choice
4.
a)
b)
c)
d)
e)
5.
a)
b)
c)
d)
e)
Here is my Quiz.java code:
public class Quiz{
String quizName;
boolean indexNumber;
public Quiz(String name)
{
quizName = name;
}
public boolean addQuestion(int index, MultipleChoice q)
{
if(index <= 5 && index >= 1)
{
indexNumber =true;
}
else
{
indexNumber =false;
}
return indexNumber;
}
public String toString()
{
MultipleChoice q1, q2, q3, q4, q5;
String result;
result = quizName+"\n\n\n";
q1 = new MultipleChoice();
q1.setIndex(1);
result += q1+"\n";
q2 = new MultipleChoice();
q2.setIndex(2);
result += q2+"\n";
q3 = new MultipleChoice();
q3.setIndex(3);
result += q3+"\n";
q4 = new MultipleChoice();
q4.setIndex(4);
resj+ x.Hmnbsp;
q5 = new MultipleChoice();
q5.setIndex(5);
&n
Computer Science
Access this solution and millions more, plus ask our experts questions 24/7
converted by Web2PDFConvert.com
Your answer
Upgrade now
Sign In
ABOUT CHEGG
Media Center
Chegg For Good
Brand Partnerships
Privacy Policy
Your CA Privacy Rights
Terms of Use
General Policies
Intellectual Property Rights
Investor Relations
RESOURCES
Site Map
Mobile
Publishers
Join Our Affiliate Program
Advertising Choices
PUBLISHER PAGES
McGraw-Hill
Cengage
Pearson
Wiley
Elsevier
HELPFUL LINKS
Return Your Books
Rent Textbooks
eTextbooks
Used Textbooks
Cheap Textbooks
College Textbooks
Sell Textbooks
Chegg Study Help
Chegg Coupon
Solutions Manual
Scholarships
Chegg Labs
Career Search
COMPANY
Chegg College Blog
Jobs
Customer Service
Give Us Feedback
Over 5 million
trees planted
2003-2014 Chegg Inc. All rights reserved.
converted by Web2PDFConvert.com