Thursday, 24 March 2005

Last week's OOP revelation was still clear in my mind during the labs today. An object can have several references to it, and will change if any of those references make changes to it. A variable is the reference to itself, and will only change in top-down sequence through the code.
Probably a perfect 4 in the lab again this week. Everything is STILL making sense. I am surprised. I probably shouldn't be though. We're still really dealing with the basics in the lectures.
Stayed until 16:38 trying to get my Dice program thing to work. Net147 sms'd me about 15min after I'd left the uni saying he'd gotten it to work. I figured it out many hours later in the evening. I didn't get it until Dooie showed me exactly how to typecast, which was what I'd spent some 30min trying to figure out with Net147 at the uni in the afternoon. Net147 sent me his working code before I figured it out, but I refused to open it. In truth, I was disappointed (again! >_<) that I hadn't been able to understand it myself. And that Net147 had gotten it working before I did (yet again). Last time, it was a concept I'd only sort of understood. That experience impressed upon me just what an object was. This time, I learnt something totally new. I suppose I should be pleased.
To typecast, in front of the value returned from a function, just put the type one wants the value to be cast to in (). eg. int randomNum = (int)(Math.random() * 20 + 1); where randomNum is an integer and Math.random() function returns a double.
While on the train on the way back, I figured out the part of the program that would call the randomise function. I might actually rename that function. As Net147 said, "randomise is usually used to reseed a random number generator", and it would be bad to have people misinterpreting that. I am going to delete the first showMessageDialog box as well. The tiny program could have a future in virtual D&D or RPG games XD
I'm going to have to use a loop to call the (now nameless) function as many times as needed, and store the values returned in an array of some kind. Then output the array as a listing of numbers to the user. Actually, I might put that in a separate function of its own, or inside the nameless function. That way I can return the array, and get main to take that and put it into a dialog box, or pass it to some other function (in case the program ever expands further than what I have in mind for it currently).
My head is now so full of programming ideas ^_^;

No comments: