3rd Challenge: Options


#1

Hello-

In regards to the third challenge, it seems as if there is/are several ways to go about it. I was curious how others are interpreting how to handle it.

My thought would be to simply display a toast if the user has already cheated on that question, then move on to the next, rather than skip past to the next question.

How are you all interpreting how to handle this thus far?

Thanks
J.


#2

Hi,

I added a boolean attribute that keeps record of ‘cheated’ status to each TrueFalse object.


#3

I created a boolean array which stored the cheated value for each index, instead of the single boolean value. By default they’re all false, but once the user cheated it gets put in the array so there’s no going back :slight_smile:

I didn’t want to create another value in the TrueFalse model because I felt that this functionality should be separated. I’m having second thoughts… could be the cheating aspect is part of the business logic.


#4

[quote=“kevinyang8398”]Hi,

I added a boolean attribute that keeps record of ‘cheated’ status to each TrueFalse object.[/quote]

Very nice solution. I didnt thought about it.


#5

I’ve actually posted that I didn’t get the question , but if my understanding is correct and the problem is that we want the user to go through the question without displaying a cheating msg if he didn’t cheat on these questions, but if he gone back the question that he cheated on then the msg will be displayed , hopefully this is the idea , if not then please tell me.

Anyways my solution is when the user presses the cheat button and then returns in the onActivityResult method it checks if he cheated or not , if he cheated then it assigns the question to the temp string and then in the checkanswer method in the if statement , basically put && and check if the current question was the same as the question that he cheated on , ofcourse you need to remember the value if he rotates or something so you won’t miss anything.


#6

I didn’t think of this either, thanks for the tip. I feel this is easier than creating another array to keep track of if one cheated on a question or not.


#7

[quote=“kevinyang8398”]Hi,

I added a boolean attribute that keeps record of ‘cheated’ status to each TrueFalse object.[/quote]

Even if it sounds as a good solution it is conceptually wrong as it merges the model with the controller (Always keep in mind the MVC pattern). If avoidable you should not try to modify the model of your program and try instead to encapsulate all the logic inside the controller.

Seems like the better answer to this challenge is the one given by DrJCFitz: http://forums.bignerdranch.com/viewtopic.php?f=402&t=6625#p19773

if you also want to solve the “fourth challenge” (once you cheated, try pressing the “cheat” button again but not the “show answer” one, go back and you’ll see how there’s no track about your previous cheating action), then implement AntonyBurt’s verbose solution to the bug: http://forums.bignerdranch.com/viewtopic.php?f=402&t=6625&start=10#p22713 and finally try slightly modifying your onCreate() method on CheatActivity to show immediately the answer to the question if the user already cheated once.


#8

[quote=“BattosaiHimura”][quote=“kevinyang8398”]
I added a boolean attribute that keeps record of ‘cheated’ status to each TrueFalse object.[/quote]

Even if it sounds as a good solution it is conceptually wrong as it merges the model with the controller (Always keep in mind the MVC pattern). If avoidable you should not try to modify the model of your program and try instead to encapsulate all the logic inside the controller.

if you also want to solve the “fourth challenge” …[/quote]

Personally I feel that putting a boolean property “DidCheat” in the TrueFalse class is a good (and proper) solution. It is, after all, tied to the question… Did the user cheat on this question? This is part of the model data. As an analogy, if you had a car object in a game and the user painted it red, would you not want to update the model data to indicate the new color? So, to me, this is the same type of scenario. What aspects of the question do we want to model? Of course the question itself and the correct answer… but also if the user cheated on it, or “painted it red”. Now if you want to use that model in another app, you are already set to be able to keep track of cheating on questions, no additional work or a new array is necessary.

In addition, this makes solving the “fourth” challenge incredibly easy. When the cheat button is pressed, just check the model data to see if that question was already cheated on, and if so remind the user they already cheated, what the answer was, and don’t go to the CheatActivity again.

Saying that “you should not try to modify the model of your program” seems kind of odd. Things in the real world change, and if we are attempting to model real world objects that the user can change in the real world, then that has to be reflected in the model. Again, back to the car model analogy. When you instantiate the car in a game, you might set a property IsBrandSpankingNew to true in the model. After driving the car off of the lot, you would want to modify that to false. So user hits button “Buy Car” and the model indicates that the car is new. Now user hits button “drive car” and you would want to change that to false. And the user may buy many cars and you want to keep track of this “new” status for all cars… what better place than in the car model? I see no difference here.

Just my .02


#9

[quote=“jgold6”][quote=“BattosaiHimura”][quote=“kevinyang8398”]
I added a boolean attribute that keeps record of ‘cheated’ status to each TrueFalse object.[/quote]

Even if it sounds as a good solution it is conceptually wrong as it merges the model with the controller (Always keep in mind the MVC pattern). If avoidable you should not try to modify the model of your program and try instead to encapsulate all the logic inside the controller.[/quote]

Personally I feel that putting a boolean property “DidCheat” in the TrueFalse class is a good (and proper) solution. It is, after all, tied to the question… [/quote]

I’m new to MVC, so I may very well be missing something, but I agree with jgold6. It seems to me that the question data (question text, true/false, whether they cheated) could/should be contained together - in the model. This would facilitate vastly different views, e.g. displaying all of the questions in a list or table, that might be tricky if some question data exists in a separate array in the controller. Perhaps naming the question class ‘TrueFalse’ is misleading once we decide to model additional details for each question, since the class name seems to imply that it only contains true/false information.

I get the sense that the line between the model and the controller can be a bit fuzzy, and that what matters most is that you make a choice for a given app and stick with it for that app. With such a simple app as GeoQuiz, it could be that keeping track of ‘cheated’ status in the controller is simpler.


#10

This can probably be debated with valid reasons for both approaches. I chose to use a boolean in the controller layer and look at it as an ephemeral condition that potentially changes with each new question. And there is also this hidden problem that exists and is somewhat easier to deal with at the controller layer:

viewtopic.php?f=402&t=9265

I think rather than be dogmatic about strict division of the MVC layers, I’d prefer to go with whatever approach makes my life and the lives of those working on my code easier.