Is an enum containing over 50 elements reasonable? | Sololearn: Learn to code for FREE!
+ 3

Is an enum containing over 50 elements reasonable?

I want to make a card game. A quartets game. For every card I wanted to create an enum of a certain class, i.e. the quartet card class. I'm going to have over 50 quartet cards. So, the enum will consist of more than 50 elements. Do you think this is a reasonable amount for an enum? My experience is that enums only contain a few elements only. The name of the enum's element are like A1, A2, A3, A4, B1, B2, etc. But the attributes of these elements are unique and don't follow a certain order. E.g. Card A1 contains these attributes with their corresponding values: Name: Porsche Max. Speed: 900 km/h Weight: 750kg Card A2 contains these attributes with their corresponding values: Name: Volvo Max. Speed: 400 km/h Weight: 550kg etc. The attributes are signifcant to the game. Also One card contains about 7 attributes. All cards share the same attribute-keys (...but of course not the same attribute-values). Language: Java

8th Apr 2017, 11:22 PM
Thanh Le
Thanh Le - avatar
6 Answers
+ 6
well, seems that there is no running from it then. i suggest making of some array or dictionary for the attributes (with overlapping indexes of the cards) and then initialize in a loop the cards, for instance make your constructor take cardName and index of attrs in the array: new Card(string cardName, index attrs) then just initialize 52 cards in a nested loop, sending a string for the name and the index
8th Apr 2017, 11:32 PM
Burey
Burey - avatar
+ 5
which values the enum are going to take? 1A, 1B, 1C, 1D, 2A,.....? 50+ (52 from what i am seeing in wiki) elements sounds like a lot of mess that could be avoided with a nested loop which create cards with the names above
8th Apr 2017, 10:59 PM
Burey
Burey - avatar
+ 4
how many attributes are there? and can you automate the process of assigning them? (is there a logic behind the attributes for each card?)
8th Apr 2017, 11:10 PM
Burey
Burey - avatar
+ 4
ok then are the attribures significant to the game? or merely represent something as a unique picture for each card?
8th Apr 2017, 11:19 PM
Burey
Burey - avatar
+ 1
yeah, something like this, but all these cards have unique attributes. @Burey
8th Apr 2017, 11:06 PM
Thanh Le
Thanh Le - avatar
+ 1
@Burey: Updated my question.
8th Apr 2017, 11:22 PM
Thanh Le
Thanh Le - avatar