• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can I tell which Array Element I'm Calling?

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1205
22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
The harder you work, the luckier you get. This tiny ad brings luck - just not good luck or bad luck.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic