teaching machines

leggitns Homework 1 Post Mortem

October 1, 2011 by . Filed under cs491 mobile, fall 2011, postmortems.

I set out to create a sort of  quiz app of sorts with allowing users the ability for users to create their own questions and group them by categories as well as play preloaded quizzes.  Unfortunately, due to time constraints, or more appropriately, poor time management on my part, I was unable to implement any question types beyond the basic 4 selection multiple choice, nor was I able to implement allowing users to create their own questions.  I was successful in implementing multiple categories to select from (and used a rather roundabout method to pass them from one category to another by create a single table in a database with a single row that stored the selected category, what can I say, it was an “11th hour” addition).  I used a database for storing “card” data (Card is the terminology i used for a quiz question as I originally planned to have “info cards” as well that were not quiz based) which proved useful and simplified things very well.  Answers are selected by buttons marked A, B, C and D with A being the first answer listed and D being the last.  The UI design was not a strong suit in this application, I have a stronger background in web based UI design so I’m not used to Android’s heavy use of XML files and the somewhat rigidity that comes with presetting your fields.  I feel like with better time management it’s possible I could have improved upon the UI.  A toast is used to inform the user if their answer is correct or incorrect and if it is incorrect, it tells them to correct answer in the toast.  Once the user reaches the end of the quiz, it tells them how many questions they got correct out of the total number of questions and allows them to restart that quiz.  If they want to go back and select a different category they can do so by hitting the hardware back button.

There are two activities in play here ( a third remained in the project but is never used, was intended for creating new quizzes).  The main activity handles the list of the categories as well as the create new quiz selection (which simply makes a toast announcing it’s selection, but performs no other activity).  There is a class for the multiple choice cards called, you guessed it, MultipleChoiceCard.  It stores the data for the cards, and has one non-getter/setter method that handles the checking of an answer.  To persist the “card” data, a CardDatabase was created.  It handles the general database stuff such as creating the card database and table, inserting data into the table, and retrieving data from the table.  It is also in this class that the above mentioned category table stuff is handled.

 

 

This is how I managed setting up the next card, or setting up the display message if the end of the cards is reached.  As you can see, if the user hits restart, the correct answers count is reset and the current card is set back to the beginning, and the quiz simply starts anew

private void setNextCard() {
if(curCard < total){
MultipleChoiceCard card = cards.get(curCard);
question.setText(card.getQuestionText());
ansA.setText(card.getAnswers()[0]);
ansB.setText(card.getAnswers()[1]);
ansC.setText(card.getAnswers()[2]);
ansD.setText(card.getAnswers()[3]);
}
else{
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
LayoutInflater inflater = getLayoutInflater();
final View dialogView = inflater.inflate(R.layout.quiz_complete, null);
dialog.setView(dialogView);

dialog.setTitle(“You got ” + correct + ” out of ” + total + ” questions correct!”);
dialog.setPositiveButton(“Restart Quiz”, new DialogInterface.OnClickListener(){

@Override
public void onClick(DialogInterface dialog, int which) {
correct = 0;
curCard = 0;
setNextCard();

}

});
dialog.setCancelable(false);
dialog.show();

}

}

 

The method that starts the quiz simply creates the listeners on the buttons, here is an example of one.

buttonA.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
MultipleChoiceCard card = cards.get(curCard);
boolean isCorrect = card.checkAnswer(0);
if(isCorrect){
correct++;
curCard++;
setNextCard();
Toast.makeText(FlashMobActivity.this,”Correct!”, Toast.LENGTH_SHORT).show();

}
else{
curCard++;
setNextCard();
String correctAns = card.getAnswers()[card.getCorrectAnswer()];
Toast.makeText(FlashMobActivity.this,”Incorrect, correct answer was: ” + correctAns, Toast.LENGTH_SHORT).show();

}
}
});
As you can see, the code isn’t the prettiest and comments are non existent in it, a side effect of poor time management.  Hopefully next time I can set out earlier on the project and implement more of my ideas in time.  I feel like this was a good starting point though and that the value of diving into a project like this definitely helped me learn some things, especially in persisting data on android and managing multiple activities.