I have my whole program written but i need to break it down into 5 seperate methods one for the values, one for the average, one for the smallest, one for the largest and one for the median. im a little confused on how to do it, thanks.
todd stolz-schroeder wrote:
I have my whole program written but i need to break it down into 5 seperate methods one for the values, one for the average, one for the smallest, one for the largest and one for the median. im a little confused on how to do it, thanks.
You have the answer in your question itself...
try to make the array reference variable as a class member. make five methods as:
getValues() //To store values in array
getAverage() //to find the average value
getSmallest() //to find the smallest value
getLargest() //to find the largest value
getMedian() //to find the Median value
Hope it helps....
SCJP-6.0 OCPJWCD-5.0
Bert Wilkinson
Ranch Hand
Joined: Oct 28, 2009
Posts: 33
posted
0
Todd,
Previous post is correct. If you have a good understanding of how to make a method and what a class variable is, this shouldn't take long. Your program is a fine first whack at the solution.
Consider what your program will need to pass the method for input information (the parameters)....this will likely be your array... and what the output will be after it is done calculating (if a calculation is to be returned.)
Badda bing...
another minor formatting point: Your class name should always be a capital letter....and to avoid confusion with an already defined class, you may want to rename it something like "MyArray". Eclipse or NetBeans let you refactor and change names real easily.
Ritesh Pareek, you have been on the Ranch long enough to know not to give out straight answers like that. It helps nobody to be given such an answer; in fact if it is found out it will earn anybody using it a mark of 0.
I hope I was in time to delete your code before it did any harm.
Campbell Ritchie wrote:It helps nobody to be given such an answer; in fact if it is found out it will earn anybody using it a mark of 0.
Or worse; it can lead to official, or unofficial, disciplinary action.
todd stolz-schroeder
Greenhorn
Joined: Feb 08, 2010
Posts: 7
posted
0
Anupam Jain wrote:
todd stolz-schroeder wrote:
I have my whole program written but i need to break it down into 5 seperate methods one for the values, one for the average, one for the smallest, one for the largest and one for the median. im a little confused on how to do it, thanks.
You have the answer in your question itself...
try to make the array reference variable as a class member. make five methods as:
getValues() //To store values in array
getAverage() //to find the average value
getSmallest() //to find the smallest value
getLargest() //to find the largest value
getMedian() //to find the Median value
Hope it helps....
Yeah get that but i dont know what the write code for it would be and where to put it I worked on this all day yesterday and just wannna get it done
Bert Wilkinson
Ranch Hand
Joined: Oct 28, 2009
Posts: 33
posted
0
Well, if you're doing this for a class, there should be some text examples of how to make class methods....it's an early concept...so you might be missing some key knowledge.
You already have the code... you just need to rearrange a bit.
your final answer will have a "main method" to get things started and then other methods to do the subtask that are outside the main method. A variable that is accessible to all of these methods is a "class variable" or "instance variable" of your class, and you'll need one of those to retain info (at this level)
this will snap right into place after you do a little work on figuring out class methods.
The code would be essentially identical to the code you have now, but in methods taking parameters and possibly returning values (depending on the method). It's unlikely anybody is going to write any of it for you (it's against JavaRanch policy). If you take a stab at it and have specific questions you're more likely to get help.
todd stolz-schroeder
Greenhorn
Joined: Feb 08, 2010
Posts: 7
posted
0
Im trying to do it but when its like this why does it return nothing??
Expanding on Anupam Jain's advice, here's an approach to consider. Move the
code you have written into the methods below. Since they are members of class
MyArray, they can all freely manipulate myArray. Jim... ...
David Newton wrote:Oh, that's obnoxious--just cut-and-paste next time, please.
Are you calling the functions? They won't call themselves.
You cant copy out of the command promt so thats what i had to do.
And i added the return command and still the same thing
As far as I can see in your main() method you are not calling any of the other methods... (not included in the quote) so its no good to expect any results... otherwise your code seems OK.
Joanne Neal
Rancher
Joined: Aug 05, 2005
Posts: 3011
9
posted
0
todd stolz-schroeder wrote:You cant copy out of the command promt so thats what i had to do.
Right click on the text area of the command prompt and select the mark option.
Left-click and hold your mouse and drag your cursor over the area you want to cut and paste - the marked area will appear black on white.
Once you have selected the whole area you want to copy, release the mouse button.
Hit return
The selected area will now be in the copy buffer and can be pasted as usual.