»
 

Go Back   ResellerRatings Store Ratings > ResellerRatings Forums > Tech Support

Reply
 
LinkBack Thread Tools Display Modes
Old 10-06-2003, 04:49 PM   #1 (permalink)
Registered User
 
The Terk's Avatar
 
Join Date: Jul 2002
Location: Texas A&M
Posts: 438
The Terk is on a distinguished road
Send a message via AIM to The Terk
new at java, cant make methods

ok, i have programmed a lil bit in c++ and i cant seem to make methods to solve my problems... such as create an array that has a user defined size and user defined values, then find the max, min, most frequent value, and etc... i can do it all in one function, but splitting it into methods is completely out of my mind.... someone please ease the pain!
*note- all these different functions are supposed to be methods

__________________

The Terk
The Terk is offline   Reply With Quote
Old 10-06-2003, 05:27 PM   #2 (permalink)
Registered User
 
krohnjw's Avatar
 
Join Date: Oct 2001
Location: ~/
Posts: 2,567
krohnjw is on a distinguished road
Send a message via AIM to krohnjw
method == function.

When using the array in java it does not need to be returned or used as a reference variable to be altered. Any alterations to the array are permanent.

It sounds like you are suposed to write a bunch of functions, with the first being setting the array.

would you care to elaborate where you are having problems here? From what I am reading you are just writing a bunch of functions (methods) like findMin, findMax, mostFrequent, etc.
krohnjw is offline   Reply With Quote
Old 10-06-2003, 05:45 PM   #3 (permalink)
Registered User
 
The Terk's Avatar
 
Join Date: Jul 2002
Location: Texas A&M
Posts: 438
The Terk is on a distinguished road
Send a message via AIM to The Terk
ok, how do i access the array through the other methods? i make a new area in the newArray() function, i ask the person how big it is using JOptionPane, parseInt it into the size, so array[size] is the new size? for loop more JOptionPanes to get the values, etc etc... how can i access that array if it is part of a different method? or does that all go in the main? srry for the nub-ness of such questions....
__________________

The Terk
The Terk is offline   Reply With Quote
Old 10-06-2003, 05:52 PM   #4 (permalink)
Registered User
 
krohnjw's Avatar
 
Join Date: Oct 2001
Location: ~/
Posts: 2,567
krohnjw is on a distinguished road
Send a message via AIM to krohnjw
It will all be in main memory. For arrays you dont have to worry about scope. For returning the max, min, etc, you will need to use return statements as those only exists inside of the method.
krohnjw is offline   Reply With Quote
Old 10-06-2003, 10:24 PM   #5 (permalink)
Banned
 
Join Date: Sep 2003
Posts: 35
pedantic is on a distinguished road
Quote:
For arrays you dont have to worry about scope.
yes, you do. though method==function.

java scope aware.
C?C++ memory location aware(hi pointers).

both OO.
pedantic is offline   Reply With Quote
Old 10-06-2003, 11:08 PM   #6 (permalink)
Registered User
 
krohnjw's Avatar
 
Join Date: Oct 2001
Location: ~/
Posts: 2,567
krohnjw is on a distinguished road
Send a message via AIM to krohnjw
In java you do not need to worry about the scope of the array inside of a method, ie it will not go out of scope when it leaves the method. Note that I did not say this applied to any other classes.

Also note we were ONLY working in Java here. We talked via AIM and got things sorted out
krohnjw is offline   Reply With Quote
Old 10-07-2003, 09:30 AM   #7 (permalink)
Registered User
 
Join Date: Oct 2001
Posts: 691
zskillz is on a distinguished road
Send a message via AIM to zskillz
well crapola!... now I'm confused.

I sure thought that if I declared and instantiated an array within method "dec_array", that once I moved outside of that method, I could not access it with other methods....


clarification please...?

-Z
zskillz is offline   Reply With Quote
Old 10-07-2003, 01:36 PM   #8 (permalink)
Registered User
 
The Terk's Avatar
 
Join Date: Jul 2002
Location: Texas A&M
Posts: 438
The Terk is on a distinguished road
Send a message via AIM to The Terk
Quote:
Originally posted by zskillz
well crapola!... now I'm confused.

I sure thought that if I declared and instantiated an array within method "dec_array", that once I moved outside of that method, I could not access it with other methods....


clarification please...?

-Z
as long as that method has a return for that array, then the main method will have that reference for the rest of ur functions to call from
__________________

The Terk
The Terk is offline   Reply With Quote
Old 10-07-2003, 03:20 PM   #9 (permalink)
Registered User
 
krohnjw's Avatar
 
Join Date: Oct 2001
Location: ~/
Posts: 2,567
krohnjw is on a distinguished road
Send a message via AIM to krohnjw
We were refering to arrays declared in main and accessed in other methods.
krohnjw is offline   Reply With Quote
Old 10-07-2003, 10:06 PM   #10 (permalink)
Registered User
 
The Terk's Avatar
 
Join Date: Jul 2002
Location: Texas A&M
Posts: 438
The Terk is on a distinguished road
Send a message via AIM to The Terk
Quote:
Originally posted by krohnjw
We were refering to arrays declared in main and accessed in other methods.
heres a function for ya:
public static void main(String[] args)
{
I am nub!;
System.exit(0);
}
__________________

The Terk
The Terk is offline   Reply With Quote
Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Most Active Discussions

Recent Discussions

All times are GMT -6. The time now is 02:46 AM.