0

I have an entire program wrote, but I'm having problems with the getMethod. I need a get method which will receive the position of the variable (1,2, or 3) and will then return the variable at that position. Here's an example of the call to the method: System.out.println(dog.getFido(2));

I've tried multiple variations, but none of the codes have worked. Can someone point me in the right direction. I've looked for tutorials and examples of this online, but I not even sure I'm using the right keywords for the search.

I appreciate any help you can give me.

Thanks!

Edited by darling332001: n/a

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by mikeNIkesT
0

I need a get method which will receive the position of the variable (1,2, or 3) and will then return the variable at that position.

Sounds like an application for an array. Change the word "position" to index and 'variable' to element and you're talking about arrays.
An array holds elements. Each element is at an index position, starting from 0 to the number of elements minus 1.
elementAtOne = theArray[1]; // returns variable/element at position/index one

Edited by NormR1: n/a

0

Ah I was wondering why his getFido method included a parameter. Good call on the array. It might be in your best interest to post part the code in question if you are still confused or your question was not answered!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.