• Post Reply Bookmark Topic Watch Topic
  • New Topic

Iterating through objects?  RSS feed

 
John Boland
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello! I am new to these forums and the Java programming language. Basically, I am trying to create a new object of class Arenas with several variables of different types. This is for a Minecraft plugin for a server (irrelevant), and basically on command /join (arenaName) the code checks to make sure that the arenaName has been defined in config and then is supposed to iterate through all objects of Arenas and check which one has that arenaName. If one doesn't exist, it creates an object and defines the String arenaName to that name. If there isn't a way to do this, could you maybe come up with a better idea on how to organize this? The problem I'm facing is that the number of arenas and name of the arenas is definable by config, so I cannot just name a bunch of objects, because I don't know how many there need to be.





 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should (at least) have two classes here, one for Arena, which has a name, and another Arenas to manage a collection of objects of type Arena.
 
John Boland
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:You should (at least) have two classes here, one for Arena, which has a name, and another Arenas to manage a collection of objects of type Arena.


Can you go a bit into more detail. I'm really confused on this, sorry .

Should I make like a map with the arenaName or what am I supposed to do? I understand making hashmaps, and lists, but I don't really get what you're trying to say, or at least how this would solve my problem.
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you've got "Arenas", plural, where it should be "Arena", singular. Then, sure use a HashMap if you're familiar with that and manage the map outside of the Arena class.
 
John Boland
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:Well, you've got "Arenas", plural, where it should be "Arena", singular. Then, sure use a HashMap if you're familiar with that and manage the map outside of the Arena class.


Like this?



Sorry that I've asked so many questions xD
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Boland wrote:
Carey Brown wrote:Well, you've got "Arenas", plural, where it should be "Arena", singular. Then, sure use a HashMap if you're familiar with that and manage the map outside of the Arena class.


Like this?



Sorry that I've asked so many questions xD


Exactly.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

You are not asking too many questions. We are more likely to find people asking too few questions or telling us too little and we have to prise the whole story out of them
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!