Brainstorming

Question: Describe how the use of an array of objects could benefit your program, with examples. 

Answer: I'm currently using them, so I guess I'll just explain how they helped in making my program more efficient. Each object contains the question, the answer, the boolean value to see whether it has been answered or not, and then a fact about the question or the answer. So whenever I'm displaying something to the screen, I always take it from that array - it's usually the question. So when I'm checking or answers, I always use the equals method that I wrote and compare it to that of the answer. After the question is answered - it doesn't matter right or wrong, this is when I change the answered value to it's opposite value, which means that the question has already been answered and the user cannot answer it again. If the user answers the question in correctly, I always display the "fun fact" to make them feel better - more knowledgable. Anyways, this is much more efficient than using variables because the number of variables you would need to store all the information would be a headache. Even if we had array of Strings for the question, answer and fact, array of booleans for the answered, it would still be quite inefficient because it will be hard to tell the index numbers apart. 

Using an array of objects makes the information all instilled in the computer's memory, so it doesn't have to be recreated again and again. It is created once - and referred back to constantly, which in turn, ends up saving memory. 

In Harry Potter Jeopardy Version 1.0, it kept crashing because there were way too many variables being created at the same time and a method never ended naturally. But the array helps it take up a lot less space, and allows the program to function much better. 

When the user uses the program, they can interact using Buttons and JTextFields. 

If they have already answered the question, one of the values will turn false. The button will also be un-pressable because they will want to try to interact with a question that they have already answered. 


No comments:

Post a Comment