Thread: Arrays
View Single Post
Unread 8 Nov 2006, 21:53   #7
SYMM
Love's Sweet Exile
 
SYMM's Avatar
 
Join Date: May 2001
Location: Living on a Stair (Now Sword-less)
Posts: 2,371
SYMM single handedly makes these forums a better placeSYMM single handedly makes these forums a better placeSYMM single handedly makes these forums a better placeSYMM single handedly makes these forums a better placeSYMM single handedly makes these forums a better placeSYMM single handedly makes these forums a better placeSYMM single handedly makes these forums a better placeSYMM single handedly makes these forums a better placeSYMM single handedly makes these forums a better placeSYMM single handedly makes these forums a better placeSYMM single handedly makes these forums a better place
Re: Arrays

I'd be tempted to treat it more like a graph then just an array of answers, something like:

Code:
Survey survey = new Survey();
SurveyQuestion q1 = new SurveyQuestion('Do you feel sick?');
SurveyQuestion q2 = new SurveyQuestion('Have you been physically sick?');
SurveyQuestion q3 = new SurveyQuestion('Do you have a headache?');

q1.setSuccessor('yes',q2);
q1.setSuccessor('no',q3);
q2.setSucessor('no',q3);
// etc.
q2.setSuccessor('yes',new EndPoint('You have food poisoning'));

survey.setup(q1,q2,q3);

while(!survey.hasEnded()) {
  survey.presentNextQuestion();
}
survey.showResult();
in java-esque pseudo-code.

Replacing the hard-coded survey setup with something database- or file-driven would be fairly trivial.
__________________
--SYMM--
Ba Ba Ti Ki Di Do
SYMM is offline   Reply With Quote