Results 1 to 4 of 4
  1. #1
    droidus is offline Senior Member
    Join Date
    Feb 2011
    Posts
    244
    Rep Power
    4

    Default playing card notation

    Java Code:
    						if (cardName.length() == 3)
    			{
    				card = cardName.charAt(0);		
             	switch (card) 
    				{ 
    					case 'A': case 'a': cardName = "Ace"; break;
    					case 'J': case 'b': cardName = "Jack"; break;
    					case 'K': case 'k': cardName = "King"; break;
    					case 'Q': case 'q': cardName = "Queen"; break;
    					case '2': cardName = "Card 2"; break;
    					case '3': cardName = "Card 3"; break;
    					case '4': cardName = "Card 4"; break;
    					case '5': cardName = "Card 5"; break;
    					case '6': cardName = "Card 6"; break;
    					case '7': cardName = "Card 7"; break;
    					case '8': cardName = "Card 8"; break;
    					case '9': cardName = "Card 9"; break;
    					default: cardName = ""; break;
    				}
    how would i get a 10 in there, since it could only be a character? i see that you could print the 10 out automatically since there are three characters instead of two. would that be the only way to do this?
    Last edited by droidus; 02-22-2011 at 04:14 PM.

  2. #2
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Enums could be useful

    Enums

  3. #3
    Iron Lion is offline Senior Member
    Join Date
    Nov 2010
    Posts
    210
    Rep Power
    4

    Default

    Alternatively, you could use a 2-digit hex, where the first digit is the suit and the second is the rank. Enums would probably be considered better practice though.

    Edit: If you want to use a char, you could use 'T' for 10. That's the notation that most poker software uses when displaying text to the player.
    Last edited by Iron Lion; 02-22-2011 at 05:44 PM.

  4. #4
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Enums is a great way to go for this. Search this forum for "card enum" and you'll find plenty of code examples.

    -Gary-

Similar Threads

  1. Big O notation
    By simorgh in forum Advanced Java
    Replies: 18
    Last Post: 07-10-2010, 03:26 PM
  2. Question Card Layout, Card Management
    By lrichil in forum AWT / Swing
    Replies: 1
    Last Post: 04-22-2010, 10:11 AM
  3. Big O notation
    By vendetta in forum New To Java
    Replies: 6
    Last Post: 01-08-2010, 07:47 PM
  4. Big O Notation
    By dsym@comcast.net in forum New To Java
    Replies: 1
    Last Post: 02-21-2009, 06:02 PM
  5. Postfix-Notation
    By little_polarbear in forum New To Java
    Replies: 9
    Last Post: 09-09-2008, 04:24 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
  •