How to initialize from a string
I am very new java and have assignment which i have completed and submitted but know that there has to be an easier way of doing this. I need to create a deck of cards, that contains the suit, description and value for each card. When the constructor is initalized the user can type in each of these values. However is there a way in java to enforce these values from a list ? So when the constructor is initialized only the correct value can be entered.
I have achieved this through a series of if statements but this appears to be a very inneficient way of doing this and I am certain in can be done from public static final variable. I have searched web and have found some suggested solutions but cannot get it work. My basic code is as follows:
private String suit;
private String description;
private int value;
/**
* Constructor for objects of class Card
*/
public Card(String description,
String suit,
int value)
{
this.description = description;
this.suit = suit;
this.value = value;
}
I appreciate any assistance on this.
Re: How to initialize from a string
Place your suits and values in an array or enum and then use loops to initialise the cards.
Re: How to initialize from a string
Thank you, i will give it a try.