Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Can I tell which Array Element I'm Calling?  RSS feed

 
Paul Carter
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the following example is there any way the method SetLevel can determine the value <NumberOfElementCalling> without me having to pass it as a parameter?

e.g. towerLevels[2].SetLevel(5, 11);


public class TowerLevel {
private int towerBrigands;

public void SetLevel(int minBrig, int varBrig) {
switch (<NumberOfElementCalling> {
case 1: towerBrigands = RandInt(16) + 17; break;
case 2: towerBrigands = RandInt(32) + 17; break;
case 3: towerBrigands = RandInt(48) + 17; break;
case 4: towerBrigands = 16; break;
}
}
}

Thanks in advance

Paul.
 
Ryan McGuire
Ranch Hand
Posts: 1143
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Short answer: No.

Longer answer: The position in the array matters to SetLevel()? Is the element at position 2 always going to be in position 2? If so, maybe that info should be reflected in a field in that object. If not, just pass the array position as another argument to SetLevel().

e.g. towerLevels[2].SetLevel(5, 11, 2);
[ October 09, 2006: Message edited by: Ryan McGuire ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!