2

Okay, here is an example of a string array that I have. As you can see, I have 15 values within the array that I want to individually assign a set number value to. The array is randomized. Is it best or even possible to create an array housing int values that I can give to each of the values within the String array? Or am I digging my own grave attempting write the program that way? This is just a small portion of the code redacted for an example of the array that I have. Also should I just go the Enum route instead?

public MyDeck() {
    int deckMin = 0;
    int deckMax = 15;

    String [] myCards = {
        "Ground Assault I", 
        "Card Example 1",
        "Card Example 2"
        "Card Example 3",
        "Card Example 4",
        "Card Example 5",
        "Card Example 6",
        "Card Example 7",
        "Card Example 8",
        "Card Example 9",
        "Card Example 10",
        "Card Example 11",
        "Card Example 12",
        "Card Example 13",
        "Card Example 14",
        "Card Example 15"
    };

    MyDeck.shuffle(myCards);

    for (int i = 0; i < myCards.length; i++) {
        System.out.print(myCards[i] + "\n ");
    }
}
michael
  • 748
  • 4
  • 10
  • Could you give an exemplar output (using `myCards` as input) for "creating an array housing int values that I can give to each of the values within the String array"? – Tsung-Ting Kuo Feb 01 '16 at 00:55
  • 1
    Thanks for the reply, I figured out a way. I was going about it all wrong. I created a class for all the card data, names, id number and the values that are applicable then another class with all of the cards listed by name (String). Still working on getting them to print with the name, id number and all the data to come with. If I can't figure it out. I may be back or more help. Thanks for the input tho. Greatly appreciated. – Cameron Dindy Feb 01 '16 at 04:57
  • my answer to http://stackoverflow.com/a/9608351/51292 may be of interest. – Ray Tayek Feb 01 '16 at 06:50

1 Answers1

1

I would recommend using a Card class to encapsulate both the name of the card and the number, and then making myCards an array of Cards. This would be expandable if you wanted to make Cards more complex in the future as well.

Sid Mani
  • 369
  • 3
  • 9