![]() |
Value-returning methods with and without a parameter
How do I do this?
Combine into one program 2 different created loops with 2 distinct methods. 1.) one value returning method with a parameter and 2.) one void method without a parameter I have two of my loop programs that I created last week. But I don't know how to modify them or combine them to do what I asked above. How can I do this. These are my loops. BREAK LOOP :
and a DO-WHILE LOOP :
I don't understand how to do this, could someone tell me how? |
Re: Value-returning methods with and without a parameter
Your question is unclear. Explain what exactly you're looking for. Also, you can always call a method from one class if you're in a different class, assuming that you know what package it is in. If they are in the same package, you can use TheClass.theMethodName(); so combining things into the same class isn't necessary much of the time. If they aren't in the same package, use thePackageName.TheClass.theMethodName();
If that didn't make any sense, consider putting your loops from each of your classes into methods. Then, in main, all you have to do is call the method name. After you do that, then go back and read what I just said above. [Side note: you can also treat main like any other method, although I don't recommend doing so.] |
Re: Value-returning methods with and without a parameter
Quote:
I don't know how to say it any other way. the two loops should all be in one program instead of 2 seperate programs with the methods I described above. |
Re: Value-returning methods with and without a parameter
So you need to refactor the two programs you have each into a function (as described in the first post) and put these functions into a single program?
|
Re: Value-returning methods with and without a parameter
Doesn't Java support function overloading
|
Re: Value-returning methods with and without a parameter
Yes, Java supports method overloading. But that can't possibly be the problem he's having, since he didn't say anything about the classes being in the same hierarchy. Also, OP, if you're unwilling to rephrase the problem you're having, then how can you expect to be helped?
|
Re: Value-returning methods with and without a parameter
Quote:
Jimbo - Yes you said it exactly. Thank you. |
| All times are GMT -5. The time now is 1:06 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC