![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Jan 2008
Posts: 54
Rep Power: 1
![]() |
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 java Syntax (Toggle Plain Text)
and a DO-WHILE LOOP java Syntax (Toggle Plain Text)
I don't understand how to do this, could someone tell me how? |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Oct 2006
Posts: 204
Rep Power: 2
![]() |
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.] |
|
|
|
|
|
#3 | |
|
Programmer
Join Date: Jan 2008
Posts: 54
Rep Power: 1
![]() |
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. |
|
|
|
|
|
|
#4 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 751
Rep Power: 3
![]() |
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?
__________________
<insert disclaimer here> <insert shameless plug for Visual Studio here> |
|
|
|
|
|
#5 | |
|
Professional Programmer
Join Date: May 2006
Location: UK - London
Posts: 329
Rep Power: 3
![]() |
Re: Value-returning methods with and without a parameter
Doesn't Java support function overloading
__________________
Quote:
|
|
|
|
|
|
|
#6 |
|
Hobbyist Programmer
Join Date: Oct 2006
Posts: 204
Rep Power: 2
![]() |
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?
|
|
|
|
|
|
#7 |
|
Programmer
Join Date: Jan 2008
Posts: 54
Rep Power: 1
![]() |
Re: Value-returning methods with and without a parameter
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|