Computer Science Canada Newbing It Out (Methods) |
Author: | .hack [ Mon Nov 01, 2004 9:43 am ] | ||
Post subject: | Newbing It Out (Methods) | ||
Ok, so I hate Java, and my teacher is convinced taht all I do is piss away time in class so he doesn't help me. Apprently everything I need is in this big yellow book written by "holt soft", yet my problems are not fixed. I am hoping that someone here can help me before I go to Holtsoft and blow up their office and destroy every ounce of java and java knowledge in this horrible world. Anyways. So I'm trying to make methods and I am uber confused. I thought I was doing it right, but I guess I'm not, I read my book and no luck. So heres my code. All I really want at this stage, si for osmone to fix it, and tell me what I did wrong / repost so I can see what I did wrong. heres my code. Its a Rock paper scissors program. And my teacher didn't help us at all learbing it (he tought us once instance of a method, and he did that incorrectly). my Gift to you: UPDATE : I got the METHODS to work! Except their values reset when they return to the main program, can u set a return point? new code.
|
Author: | wtd [ Mon Nov 01, 2004 7:46 pm ] | ||||||||||
Post subject: | |||||||||||
|
Author: | .hack [ Tue Nov 02, 2004 8:59 am ] |
Post subject: | |
My teacher won't let me use the sun API, purely because hes newb. Pretty much watever he teaches he read from the book the day brfore, then tells us not to worry about the syntax he puts on the board rarely. I'm stuck with this holtsoft bullshit, and yea I know about naming classes with 1 capital and such, I just don't really care for it myself lmao (Not to sound like a lazy bastard, but I do feel that being in this class is a waste of time, as I feel the "Java" were learning in my class is completely useless) Basically my one question remains. I have it declaring a variable in the main, which is = 0 so th program will run. THen I have it running a method where the variable number is changes by the user. but when I exit the method and return to the main the variable number gets reset to its value set in declaration in the main (0). This I don;t quit understnad, unless when using methods your supposed to somehow link them together and never go back to the main. java hurts my head. |
Author: | wtd [ Tue Nov 02, 2004 1:50 pm ] | ||||||||||
Post subject: | |||||||||||
First lesson: remove extraneous comments. Things like:
Are just comments pointing out the incredibly obvious. Use comments to explain why you're doing certain things, what you're doing. Second lesson: built-in types get passed to methods by value. So, in:
UChoice is just a copy of the value in the foo variable, not foo itself. Any changes you make to UChoice will not be reflected in foo once the function ends. Third lesson: variables can be declared anywhere inside a method. They don't all need to be declared at the start.
Can be more succinctly (and correctly) rewritten as:
And lessons get tedious, so the refined code...
|
Author: | .hack [ Wed Nov 03, 2004 8:58 am ] |
Post subject: | |
thanks for all the help, it smuch appreciated, I'll try to take it from there and see how it ends up. TTYTT I';m not really built for programming -.- +50bits |