Results 1 to 2 of 2
  1. #1
    javaMike is offline Member
    Join Date
    Nov 2007
    Rep Power

    Default add objects to list

    i created 52 cards objects from my clsCard. i.e.

    dim twoOfHearts as new clsCard
    twoOfHearts.facevalue = "2"
    twoOfHearts.suit = "Hearts"

    now i want to add them to my deck (52) as clsCard.

    what's the easiest way to add them iteratively?

  2. #2
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Houston, TX & Flint, MI
    Rep Power


    Eep you will be better off recreating your cards a different way. I'm not familiar with ENUMS but every example for a deck of cards uses them. I'm assuming you have 52 cards name faceValueOfDeck? Having it set up this way will require you to add each one individually to an array(or arrayList)

    If you redo it and have 52 card objects you can have a for loop that creates them within the loop while adding them.
    Java Code:
    for(1 to 52){
    	if(x > 0 && x <= 13)
    		if(x == 10)
    			value = "jack";
    		else if(x == 11)
    			value = "queen";
    		else if(x == 12)
    			value = "king";
    		else if(x == 13)
    			value = "ace";
    			value = x;
    			deck[x] = new Card("Clubs",value);	
    I'm sure you can work some better logic into to determine the face values(like x%13 == 0 then value = ace)

    Hope this helps
    Liberty has never come from the government.
    Liberty has always come from the subjects of government.
    The history of liberty is the history of resistance.
    The history of liberty is a history of the limitation of governmental power, not the increase of it.

Similar Threads

  1. Finding objects in a list
    By starwars in forum AWT / Swing
    Replies: 5
    Last Post: 09-11-2009, 03:42 PM
  2. List of objects
    By bubbless in forum New To Java
    Replies: 0
    Last Post: 08-01-2009, 04:21 PM
  3. List of objects
    By rekha in forum New To Java
    Replies: 6
    Last Post: 03-20-2009, 12:39 PM
  4. Replies: 1
    Last Post: 01-22-2009, 05:25 PM
  5. Getting objects from a list
    By markyoung1984 in forum New To Java
    Replies: 4
    Last Post: 03-13-2008, 11:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts