Ask your own question, for FREE!
Computer Science 7 Online
OpenStudy (anonymous):

**MEDAL + FAN** Please check my Java Programming answers! I need help!

OpenStudy (anonymous):

OpenStudy (woodrow73):

ello.

OpenStudy (anonymous):

@woodrow73 Hii, haha.

OpenStudy (woodrow73):

you know a method header looks like: public static int returnAddition(int A) and this is the body of a method: { int B = 2; int sum = A + B; return sum; }

OpenStudy (anonymous):

A few things should be noted here... -A method header can be considered a only part of (using the example above) public static int returnAddition (int ) and the signature is the other part. -You should review what data types can and cannot be returned. -Also review how static methods are actually called and used in the main method. For example, if I called int sqrt(2); you need to realize that no piece of memory was actually allocated on the stack and accordingly nothing will be stored (in truth your compiler should complain). However, interestingly enough you can call a method that returns something and immediately print it without declaring a variable. - Typically one does not name a parameter a number. For example double 25 is not correct. -Review the difference between pass by value and pass by reference in order to determine the correct answer. - Lastly, the arguments for function/methods should be separated by a comma and their data types explicitly declared. For example, (int a , int b). Hopefully this helps and sorry for the long post.

OpenStudy (woodrow73):

so the body of a method is called that method's 'signature'?

OpenStudy (anonymous):

hmmm that was terribly worded by me in fact I am kinda embarrassed that I didn't double check that because if misread it might lead to a incorrect interpretation. However, let me rephrase it, A method signature is part of the method header where as the method header is a section in the method. What you/@woodrow73 explicitly stated is indeed the method header but I wanted to point out that that these elements are sections or subsection to a larger concept.

OpenStudy (woodrow73):

ya, I just recently started learning about methods. To my knowledge you have the method modifiers(inside the method header) ie: public static the return type: primitive data or void(not sure about the list of what's valid), and the parameters which are inside the parenthesis(int A, int B) { if you would, which part of it is the signature?

OpenStudy (woodrow73):

@pipsy

OpenStudy (anonymous):

For return types typically speaking they will be a primitive type, void, or a reference to some item/object. However, in java you don't really work with pointers and all that fun stuff but if you have the time I would suggest learning about that as it will given you an idea of what is happening on a low level. As for the signature there are different definitions for a signature but generally speaking it is referring to the method name and the number and type of its parameters. For example, returnAddition(int a) is the signature for the above example.

OpenStudy (woodrow73):

thanks

OpenStudy (anonymous):

For number 3, based on what I've learned (it seems to be different depending on course) but the way my course runs a class that will not return any value, we use void

OpenStudy (anonymous):

@pipsy Thanks for you help, but I'm not sure which problems a missed. Can you tell me which ones I answered incorrectly so I can look them over?

OpenStudy (anonymous):

@Lyrae Can you help me? It's more Java Programming stuff...

OpenStudy (anonymous):

I may be able to help aswell

OpenStudy (anonymous):

@blahblah212121 That would be great! I'm drowning in this class and I'd really like to figure it out.

OpenStudy (anonymous):

Yeah im taking AP comp sci just ask

OpenStudy (anonymous):

Alright! Well, for instance, can you tell me which questions I answered incorrectly in the images I posted?

OpenStudy (lyrae):

1, 3, 5, 6, 7, 8, 9 (unchecked), 10 need some review.

OpenStudy (anonymous):

Oh man, I really bombed this one. UUUgh.

OpenStudy (anonymous):

1.) Statements?

OpenStudy (lyrae):

Yeah

OpenStudy (anonymous):

3.) Void?

OpenStudy (lyrae):

yup

OpenStudy (lyrae):

Read pipsy and woodrows73 conversation above. They answer atleast half of your questions. Also read some short tutorial on java methods and you'll fix all of them in a heartbeat http://www.tutorialspoint.com/java/java_methods.htm for example

OpenStudy (anonymous):

Thanks for your help :D

OpenStudy (anonymous):

#5 is confusing me a bit. Is 5.) int max(5, 3) = result;?

OpenStudy (lyrae):

Naah, how would you assign a regular integer to variable; 5 for example?

OpenStudy (anonymous):

So perhaps int result = max (5, 3);

OpenStudy (lyrae):

yeah :)

OpenStudy (anonymous):

Right on! :) Another hard question. 6.) int result = min (2, 9);

OpenStudy (anonymous):

and 7.) public static double sqrt(double num)

OpenStudy (lyrae):

7 is correct, 6 is not.

OpenStudy (anonymous):

8.) public static int sum (int a, int b) Alright, I'll have another look at 6.

OpenStudy (lyrae):

In 6 you should print the value

OpenStudy (lyrae):

8 is correct!

OpenStudy (anonymous):

6.) System.out.println(min(2), min(9));

OpenStudy (lyrae):

Nope

OpenStudy (lyrae):

Now you're guessing :P

OpenStudy (lyrae):

System.out.println() is a method that prints something

OpenStudy (anonymous):

You know, I had a feeling it was System.out.println(min(2, 9)); to be honest XD

OpenStudy (lyrae):

Haha that's better!

OpenStudy (anonymous):

Thanks for helping me with this, again :) Two more questions left.

OpenStudy (lyrae):

Np :)

OpenStudy (anonymous):

Well, for #9, I know that a pass-by-value is copied into a location being used to hold the formal parameter's value during method/function execution. I'm not sure which option best fits the definition. Maybe 9.) C?

OpenStudy (anonymous):

Also, 10.) public static void print ( String word; count)

OpenStudy (lyrae):

9 yes, 10 no

OpenStudy (anonymous):

Oh wait wait wait. 10.) I just noticed that B had a comma rather then a semicolon. So it's B, (String word, int count)

OpenStudy (anonymous):

Thank you so much, Lyrae! :) Coming to the rescue, once again.

OpenStudy (lyrae):

Yes

OpenStudy (lyrae):

Aah np :)

OpenStudy (lyrae):

Did you get 10/10 this time? :P

OpenStudy (anonymous):

I did! With your help, of course :D

OpenStudy (lyrae):

Sweet! Haha all I do is bashing your work :P You're the one answering the questions ;)

OpenStudy (anonymous):

What?? My grade wouldn't be as good as it is without your help, lol. I've tried asking the teacher for help, too. He always says something like "Go back in the book." or "Search for the tutorials on YouTube." He's not very helpful, haha.

OpenStudy (lyrae):

Haha thx :) I recognice that rhetoric, it's probably a trait all programing teachers share :P

OpenStudy (anonymous):

Maybe! I do online school though, and some of my teachers refrain me to the textbook for everything.

OpenStudy (lyrae):

That's interesting; isn't a theachers job to teach? O well, one could debate this topic for hours. Anyway, if you have other questions regaring CS/programming I'll be happy to help :) that's why I'm here after all!

OpenStudy (anonymous):

Thanks again!

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!