Page 1 of 2 12 LastLast
Results 1 to 20 of 30
  1. #1
    rushtojess is offline Member
    Join Date
    Apr 2015
    Posts
    21
    Rep Power
    0

    Default Implementing a card game in JAVA - Help with deck

    Hi all,

    I am hoping you can help me with a problem I am facing with a JAVA code needed for my assignment.
    We are implementing a Card Game.. There is a Card Class which i have not included in the code below .
    We have a Dec class that has various arrays..
    private Card[] masterPack >> Is a master Pack that is initialized once and has all the 52 cards.
    private Card[] cards >> Is the array that has the card values from masterPack array.

    My problem is :
    After I called the Deck object D1, it goes to the Deck COnstrucutor OK
    It then populates the values of masterPack as per the allowmasterPack method.
    Then it stores the values of masterPack into cards array in the init method..
    I get an exception when line below is executed..

    cards[pack * 52 + k]= masterPack[k];

    I get a java.lang.NullPointerException error..
    Please can anyone help me. Much appreciated

    public class debug
    {
    public static void main(String[] args)
    {
    int pack = 1;
    Dec D1;
    D1 = new Dec(pack);
    }
    }

    class Card
    {
    // type and constants
    public enum Suit { clubs, diamonds, hearts, spades }

    // private data
    private char value;
    private Suit suit;
    boolean errorFlag;

    // 4 overloaded constructors
    public Card(char value, Suit suit)
    {
    set(value, suit);
    }

    public Card(char value)
    {
    this(value, Suit.spades);
    }
    public Card()
    {
    this('A', Suit.spades);
    }
    // copy constructor
    public Card(Card card)
    {
    this(card.value, card.suit);
    }

    // mutators
    public boolean set(char value, Suit suit)
    {
    char upVal; // for upcasing char

    // convert to uppercase to simplify
    upVal = Character.toUpperCase(value);

    if ( !isValid(upVal, suit))
    {
    errorFlag = true;
    return false;
    }

    // else implied
    errorFlag = false;
    this.value = upVal;
    this.suit = suit;
    return true;
    }

    // accessors
    public char getVal()
    {
    return value;
    }

    public Suit getSuit()
    {
    return suit;
    }

    public boolean getErrorFlag()
    {
    return errorFlag;
    }

    public boolean equals(Card card)
    {
    if (this.value != card.value)
    return false;
    if (this.suit != card.suit)
    return false;
    if (this.errorFlag != card.errorFlag)
    return false;
    return true;
    }

    // stringizer
    public String toString()
    {
    String retVal;

    if (errorFlag)
    return "** illegal **";

    // else implied

    retVal = String.valueOf(value);
    retVal += " of ";
    retVal += String.valueOf(suit);

    return retVal;
    }

    // helper
    private boolean isValid(char value, Suit suit)
    {
    char upVal;

    // convert to uppercase to simplify (need #include <cctype>)
    upVal = Character.toUpperCase(value);

    // check for validity
    if (
    upVal == 'A' || upVal == 'K'
    || upVal == 'Q' || upVal == 'J'
    || upVal == 'T'
    || (upVal >= '2' && upVal <= '9')
    )
    return true;
    else
    return false;
    }
    }

    class Dec
    {

    public static final int MAX_CARDS = 312;
    private Card[] masterPack;
    private Card[] cards;
    private int topCard;
    private int numPacks = 1;
    public static int count;

    private void allocateMasterPack()
    {
    System.out.println("allocateMasterPack() activated");
    Card[] masterPack = new Card[52];

    System.out.println(" Construting the masterPAck");
    for (Card.Suit st: Card.Suit.values())
    {
    masterPack[13 * k] = new Card('A', st);
    for (val='2',j = 1; val<='9'; val++, j++)
    masterPack[(13 * k) + j] = new Card(val, st);
    masterPack[(13* k)+ 9] = new Card('T', st);
    masterPack[(13* k)+ 10]= new Card('J', st);
    masterPack[(13* k)+ 11]= new Card('Q', st);
    masterPack[(13* k)+ 12]= new Card('K', st);
    k++;
    }

    public Dec(int val)
    {
    allocateMasterPack();
    System.out.println("Printing the values in constructor");
    cards = new Card[52];
    for (int k = 0; k < cards.length; k++)
    cards[k]= new Card();
    init(val);

    }

    public void init(int val)
    {
    int k, pack;

    if (val < 1 || val > 6)
    val= 1;

    // hand over the masterPack cards to our deck
    for (pack = 0; pack < val;pack++)
    for (k = 0; k < 52; k++)
    cards[pack * 52 + k]= masterPack[k]; >> Geting an error here -- Null Pointer exception
    this.numPacks = val;
    topCard = val* 52;
    }
    }

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,995
    Rep Power
    9

    Default Re: Implementing a card game in JAVA - Help with deck

    You THINK you are initializing the Card[] masterPack of your class, but in reality, you are initializing the Card[] marsterPack INSIDE the method. Drop the Card[] from the line in the method to make sure you are referencing the field, instead of the local variable. After the method the masterPack field is still null because of this, and so masterPack[i] will result in said NullPointerException.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  3. #3
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,995
    Rep Power
    9

    Default Re: Implementing a card game in JAVA - Help with deck

    Also, the same problem goes for variables int k and int val. They are declared as local variables or method parameters in public void init(...), so that means the "scope" as it's called is the method, and your allocateMasterPack method can't use those.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  4. #4
    rushtojess is offline Member
    Join Date
    Apr 2015
    Posts
    21
    Rep Power
    0

    Default Re: Implementing a card game in JAVA - Help with deck

    Did you mean to remove the Card[] in the line Card[] masterPack = new Card[52]; in allowmasterPack.
    I did that , and it threw an error..
    MasterPack array needs to be initialized before it cna be used.
    I have been working on this for 2 days. i dont know what it cna be

  5. #5
    rushtojess is offline Member
    Join Date
    Apr 2015
    Posts
    21
    Rep Power
    0

    Default Re: Implementing a card game in JAVA - Help with deck

    masterPack is one of the member fields of the Dec class so it won't be mistaken as a local variable in any mentod i would have thought?

  6. #6
    rushtojess is offline Member
    Join Date
    Apr 2015
    Posts
    21
    Rep Power
    0

    Default Re: Implementing a card game in JAVA - Help with deck

    I have jsut simplified the construtor to jsut print the value of masterPack[0].
    I get an exception, the problem is masterPack is not accepted in the Construtor.. i dont know why?

    public Dec(int val)
    {
    allocateMasterPack();
    System.out.println("Printing the values in constructor");
    cards = new Card[52];
    for (int k = 0; k < cards.length; k++)
    cards[k]= new Card();
    System.out.println ( masterPack[0]);
    // init(val);

    }

    Output:
    ======
    allocateMasterPack() activated
    Construting the masterPAck
    Value at index 8 is9 of Clubs
    Printing the values now
    Value at index 0 isA of Clubs

    Printing the values now
    Value at index 1 is2 of Clubs

    Exception in thread "main" Printing the values now
    Value at index 2 is3 of Clubs

    Printing the values now
    Value at index 3 is4 of Clubs

    Printing the values now
    Value at index 4 is5 of Clubs

    Printing the values now
    Value at index 5 is6 of Clubs

    Printing the values now
    Value at index 6 is7 of Clubs

    Printing the values now
    Value at index 7 is8 of Clubs

    Printing the values now
    Value at index 8 is9 of Clubs

    Printing the values now
    Value at index 9 isT of Clubs

    Printing the values now
    Value at index 10 isJ of Clubs

    Printing the values now
    Value at index 11 isQ of Clubs

    Printing the values now
    Value at index 12 isK of Clubs

    Printing the values now
    Value at index 13 isA of diamonds

    Printing the values now
    Value at index 14 is2 of diamonds

    Printing the values now
    Value at index 15 is3 of diamonds

    Printing the values now
    Value at index 16 is4 of diamonds

    Printing the values now
    Value at index 17 is5 of diamonds

    Printing the values now
    Value at index 18 is6 of diamonds

    Printing the values now
    Value at index 19 is7 of diamonds

    Printing the values now
    Value at index 20 is8 of diamonds

    Printing the values now
    Value at index 21 is9 of diamonds

    Printing the values now
    Value at index 22 isT of diamonds

    Printing the values now
    Value at index 23 isJ of diamonds

    Printing the values now
    Value at index 24 isQ of diamonds

    Printing the values now
    Value at index 25 isK of diamonds

    Printing the values now
    Value at index 26 isA of Hearts

    Printing the values now
    Value at index 27 is2 of Hearts

    Printing the values now
    Value at index 28 is3 of Hearts

    Printing the values now
    Value at index 29 is4 of Hearts

    Printing the values now
    Value at index 30 is5 of Hearts

    Printing the values now
    Value at index 31 is6 of Hearts

    Printing the values now
    Value at index 32 is7 of Hearts

    Printing the values now
    Value at index 33 is8 of Hearts

    Printing the values now
    Value at index 34 is9 of Hearts

    Printing the values now
    Value at index 35 isT of Hearts

    Printing the values now
    Value at index 36 isJ of Hearts

    Printing the values now
    Value at index 37 isQ of Hearts

    Printing the values now
    Value at index 38 isK of Hearts

    Printing the values now
    Value at index 39 isA of Spades

    Printing the values now
    Value at index 40 is2 of Spades

    Printing the values now
    Value at index 41 is3 of Spades

    Printing the values now
    Value at index 42 is4 of Spades

    Printing the values now
    Value at index 43 is5 of Spades

    Printing the values now
    Value at index 44 is6 of Spades

    Printing the values now
    Value at index 45 is7 of Spades

    Printing the values now
    Value at index 46 is8 of Spades

    Printing the values now
    Value at index 47 is9 of Spades

    Printing the values now
    Value at index 48 isT of Spades

    Printing the values now
    Value at index 49 isJ of Spades

    Printing the values now
    Value at index 50 isQ of Spades

    Printing the values now
    Value at index 51 isK of Spades

    Printing the values in constructor
    java.lang.NullPointerException
    at Dec.<init>(debug.java:195)
    at debug.main(debug.java:7)

  7. #7
    rushtojess is offline Member
    Join Date
    Apr 2015
    Posts
    21
    Rep Power
    0

    Default Re: Implementing a card game in JAVA - Help with deck

    I have jsut simplified the construtor to jsut print the value of masterPack[0].
    I get an exception, the problem is masterPack is not accepted in the Construtor.. i dont know why?

    public Dec(int val)
    {
    allocateMasterPack();
    System.out.println("Printing the values in constructor");
    cards = new Card[52];
    for (int k = 0; k < cards.length; k++)
    cards[k]= new Card();
    System.out.println ( masterPack[0]);
    // init(val);

    }

    Output:
    ======
    allocateMasterPack() activated
    Construting the masterPAck
    Value at index 8 is9 of Clubs
    Printing the values now
    Value at index 0 isA of Clubs

    Printing the values now
    Value at index 1 is2 of Clubs

    Exception in thread "main" Printing the values now
    Value at index 2 is3 of Clubs

    Printing the values now
    Value at index 3 is4 of Clubs

    Printing the values now
    Value at index 4 is5 of Clubs

    Printing the values now
    Value at index 5 is6 of Clubs

    Printing the values now
    Value at index 6 is7 of Clubs

    Printing the values now
    Value at index 7 is8 of Clubs

    Printing the values now
    Value at index 8 is9 of Clubs

    Printing the values now
    Value at index 9 isT of Clubs

    Printing the values now
    Value at index 10 isJ of Clubs

    Printing the values now
    Value at index 11 isQ of Clubs

    Printing the values now
    Value at index 12 isK of Clubs

    Printing the values now
    Value at index 13 isA of diamonds

    Printing the values now
    Value at index 14 is2 of diamonds

    Printing the values now
    Value at index 15 is3 of diamonds

    Printing the values now
    Value at index 16 is4 of diamonds

    Printing the values now
    Value at index 17 is5 of diamonds

    Printing the values now
    Value at index 18 is6 of diamonds

    Printing the values now
    Value at index 19 is7 of diamonds

    Printing the values now
    Value at index 20 is8 of diamonds

    Printing the values now
    Value at index 21 is9 of diamonds

    Printing the values now
    Value at index 22 isT of diamonds

    Printing the values now
    Value at index 23 isJ of diamonds

    Printing the values now
    Value at index 24 isQ of diamonds

    Printing the values now
    Value at index 25 isK of diamonds

    Printing the values now
    Value at index 26 isA of Hearts

    Printing the values now
    Value at index 27 is2 of Hearts

    Printing the values now
    Value at index 28 is3 of Hearts

    Printing the values now
    Value at index 29 is4 of Hearts

    Printing the values now
    Value at index 30 is5 of Hearts

    Printing the values now
    Value at index 31 is6 of Hearts

    Printing the values now
    Value at index 32 is7 of Hearts

    Printing the values now
    Value at index 33 is8 of Hearts

    Printing the values now
    Value at index 34 is9 of Hearts

    Printing the values now
    Value at index 35 isT of Hearts

    Printing the values now
    Value at index 36 isJ of Hearts

    Printing the values now
    Value at index 37 isQ of Hearts

    Printing the values now
    Value at index 38 isK of Hearts

    Printing the values now
    Value at index 39 isA of Spades

    Printing the values now
    Value at index 40 is2 of Spades

    Printing the values now
    Value at index 41 is3 of Spades

    Printing the values now
    Value at index 42 is4 of Spades

    Printing the values now
    Value at index 43 is5 of Spades

    Printing the values now
    Value at index 44 is6 of Spades

    Printing the values now
    Value at index 45 is7 of Spades

    Printing the values now
    Value at index 46 is8 of Spades

    Printing the values now
    Value at index 47 is9 of Spades

    Printing the values now
    Value at index 48 isT of Spades

    Printing the values now
    Value at index 49 isJ of Spades

    Printing the values now
    Value at index 50 isQ of Spades

    Printing the values now
    Value at index 51 isK of Spades

    Printing the values in constructor
    java.lang.NullPointerException
    at Dec.<init>(debug.java:195)
    at debug.main(debug.java:7)

  8. #8
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,995
    Rep Power
    9

    Default Re: Implementing a card game in JAVA - Help with deck

    You must be looking at other code than me, because when I throw this code in an editor, it complains about "field masterPack is never assigned" (which is true since you only assign a local variable), all the non-existing variables (k, j and val), and you have declared the constructor public Dec(int val) inside the method allocateMasterPack. The curly braces don't match.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  9. #9
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,995
    Rep Power
    9

    Default Re: Implementing a card game in JAVA - Help with deck

    Quote Originally Posted by rushtojess View Post
    masterPack is one of the member fields of the Dec class so it won't be mistaken as a local variable in any mentod i would have thought?
    It will be mistaken if you declare it AGAIN inside a method.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  10. #10
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,995
    Rep Power
    9

    Default Re: Implementing a card game in JAVA - Help with deck

    You can output all you want, but that is the output of the masterPack local variable inside the method. Try running over this masterPack field AFTER you called allocateMasterPack(). It will be null.
    Java Code:
    public class Deck {
       private Card[] masterPack;
    
       public Deck() {
          init();
          System.out.println("masterpack is null? = " + (masterPack == null) ); //What is masterPack now?
          System.out.println("masterpack length? = " + (masterPack.length) ); //NullPointerException here since it's not initialized
       }
    
       public void init() { 
          Card[] masterPack = new Card[52]; //Remove the Card[] part and see what happens next
       }
    }
    Oh, and see the pretty colours here? That's because of the [code][/code]] tags I used. Make sure to add those around your code it you post, well, code.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  11. #11
    rushtojess is offline Member
    Join Date
    Apr 2015
    Posts
    21
    Rep Power
    0

    Default Re: Implementing a card game in JAVA - Help with deck

    Forget the init and all for now..
    Let the Dec construtor have only the code below..
    What changes should i make in the allowmasterPack to make it work? PLease help

    class Dec
    {

    public static final int MAX_CARDS = 312;
    private Card[] masterPack;
    private Card[] cards;
    private int topCard;
    private int numPacks = 1;
    public static int count;

    private void allocateMasterPack()
    {
    System.out.println("allocateMasterPack() activated");
    Card[] masterPack = new Card[52];

    System.out.println(" Construting the masterPAck");
    for (Card.Suit st: Card.Suit.values())
    {
    masterPack[13 * k] = new Card('A', st);
    for (val='2',j = 1; val<='9'; val++, j++)
    masterPack[(13 * k) + j] = new Card(val, st);
    masterPack[(13* k)+ 9] = new Card('T', st);
    masterPack[(13* k)+ 10]= new Card('J', st);
    masterPack[(13* k)+ 11]= new Card('Q', st);
    masterPack[(13* k)+ 12]= new Card('K', st);
    k++;
    }

    public Dec(int val)
    {
    allocateMasterPack();
    System.out.println(masterPack[5]);
    }

  12. #12
    rushtojess is offline Member
    Join Date
    Apr 2015
    Posts
    21
    Rep Power
    0

    Default Re: Implementing a card game in JAVA - Help with deck

    Can you try this code in your editor and see if u are getting an error..
    If not , what changes have u made?

  13. #13
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,995
    Rep Power
    9

    Default Re: Implementing a card game in JAVA - Help with deck

    Use [code][/code] tags around your code!!!! That is not a question!

    1) Make sure your braces match up, cos they don't. You need an extra brace after k++;}
    2) Remove the Card[] from Card[] masterPack = new Card[52]; so it reads
    Java Code:
    masterPack = new Card[52];
    As I have explained, declaring it like you do makes masterPack a LOCAL variable to the method. Your FIELD will be untouched.
    3) Variables k, j and val do not exist. Not in the method allocateMasterPack.
    Last edited by SurfMan; 04-20-2015 at 12:26 AM.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  14. #14
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Implementing a card game in JAVA - Help with deck

    You did not read the forum rules as I suggested. Please go back and edit your posts and place your code between [code][/code] tags.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  15. #15
    rushtojess is offline Member
    Join Date
    Apr 2015
    Posts
    21
    Rep Power
    0

    Default Re: Implementing a card game in JAVA - Help with deck

    Thanks a lot for the help.
    it makes sense and its working.
    Thanks a ton.

    Much apreciated

  16. #16
    rushtojess is offline Member
    Join Date
    Apr 2015
    Posts
    21
    Rep Power
    0

    Default Re: Implementing a card game in JAVA - Help with deck

    Hi,

    Any anyone tell me where I can see the forum rules.. i want to know how to place code between tags.

    Thanks
    Jessi

  17. #17
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Implementing a card game in JAVA - Help with deck

    Quote Originally Posted by rushtojess View Post
    Hi,

    Any anyone tell me where I can see the forum rules.. i want to know how to place code between tags.

    Thanks
    Jessi
    Go to the home page and click on FAQ. But I will tell you here how to use code tags the easy way. When you edit or past code, go do the advanced editor (lower right when you are editing). You will see some additional icons in the editor toolbar. Highlight your code with the mouse and click #. That will add code tags to your highlighted code.

    For other available tags, go to the bottom of the forum page in posting permissions where you will see BBCodes highlighted. Open that link to see other tags. Click on the tag to see examples of how to use it.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  18. #18
    rushtojess is offline Member
    Join Date
    Apr 2015
    Posts
    21
    Rep Power
    0

    Default Re: Implementing a card game in JAVA - Help with deck

    Thanks Jim.Got it now.

  19. #19
    rushtojess is offline Member
    Join Date
    Apr 2015
    Posts
    21
    Rep Power
    0

    Default Re: Implementing a card game in JAVA - Help with deck

    Continuing with the card game now :)

    So the deck has been created now and now I want the hand objects to take a card from the deck object one at a time until there are no more cards left in the Deck object.
    The Hand class has already been written.
    My problem is

    I am storing the hand objects in an array list and using a for loop to picj each hand and then dealing a card onto it..
    Code:

    Java Code:
    Deck D3;
    	D3 = new Deck();
    	Hand h1,h2,h3;
    	h1 = new Hand();
    	h2 = new Hand();
    	h3 = new Hand();
    	List <Hand> list = new ArrayList <Hand>();
    	list.add(h1);
    	list.add(h2);
    	list.add(h3);
    	
    	int card_length = D3.getTopCard();
    	System.out.println(" The card length is " + card_length);
    	
    	while (card_length > 0)
    	{
    		for (Hand currHand : list) 
    		{
    			System.out.println(" the current hand value is " +  currHand );
    		         currHand.takeCard(D3.dealCard());
    		          System.out.println(" the current hand value is " + currHand.playCard());
    		}
    		card_length= card_length -3 ;
    		System.out.println("The card length now is " + card_length);
    	}
    The problem is in line
    System.out.println(" the current hand value is " + currHand );
    CurrHand should be h1 first but it displays as nothing..

    There is an issue with the list here?
    Can anyone please help me.

    Many Thanks

  20. #20
    rushtojess is offline Member
    Join Date
    Apr 2015
    Posts
    21
    Rep Power
    0

    Default Re: Implementing a card game in JAVA - Help with deck

    The Hand class is defined as below, can anyone help me figure out why the hand objects are not seen in the array list.
    I tired using normal intergers in the array and that displays OK..
    IS there something I am missing.

    Thanks

    Java Code:
    class Hand
    {
    	public int MAX_CARDS = 50;
    	private Card[] mycards;
    	private  int numcards = 0;
    
    	//Default constructor,hand is initially empty
    	public Hand()
    	{
    		mycards = new Card[MAX_CARDS];
    	}
    
    	//Method to remove all cards from the hand
    	public void resetHand()
    	{
    		numcards = 0;
    	}
    
    	//Method to add a card to the next available position 
    	public boolean takeCard(Card Cardx)
    	{
    		int numcard_value = getNumcards();
    		mycards[numcard_value] = Cardx;
    		numcards++;
    		return true;
    	}
    
    	//Method to return and remove the card .
    	public Card playCard() 
    	{
    		Card topcard;
    		topcard = new Card();
    		int cardlength = getNumcards();
    		int actual_len = cardlength -1 ;
    		for (int k=actual_len;k>=0;k--)
    		{
    			topcard = mycards[k];
    			actual_len--;
    			numcards--;
    		
    		}
    		return topcard;
    	}
    
    	// Method to display the cards
    	public String toString()
    	{
    		int cardlength = numcards;
    		String cardstring = "";
    		for (int i=0;i<cardlength;i++)
    		{
    			String stringval =  String.valueOf(mycards[i]);
    			cardstring += stringval + "," ;
    		}
    		return cardstring;
    	}
    
    	// Accessors for numcards
    	public int getNumcards()
    	{
    		return numcards;
    	}
    
    	// Accessors for individual card
    	public Card inspectCard(char k)
    	{
    		char upVal;
    		String index = String.valueOf(k);
    		int value = Integer.parseInt(index);
    		System.out.println("Inspecting  card " + mycards[value]);
    		char Getvaluetocheck = mycards[value].getVal();
    		upVal = Character.toUpperCase(Getvaluetocheck);
    		if (upVal == 'A' || upVal == 'K' || upVal == 'Q' || upVal == 'J'
    				|| upVal == 'T'|| (upVal >= '2' && upVal <= '9'))
    		{
    			System.out.println (" The card is legal");
    			return mycards[value];
    		}else  {
    			System.out.println (" The card is illegal");
    			mycards[value].set('0',mycards[value].getSuit());
    			System.out.println(" value of the illegal card is " + mycards[value]);
    			return mycards[value];
    		}
    	} 
    
    }

Page 1 of 2 12 LastLast

Similar Threads

  1. Deck output with Card class help
    By steve0827 in forum New To Java
    Replies: 5
    Last Post: 12-10-2012, 12:41 AM
  2. Want two deck card in my applet
    By ganesh.gothi@gmail.com in forum Java Applets
    Replies: 4
    Last Post: 04-16-2012, 01:21 PM
  3. Replies: 11
    Last Post: 11-25-2011, 04:56 AM
  4. Creating a card class for a Deck of cards
    By adjit in forum New To Java
    Replies: 13
    Last Post: 04-06-2011, 10:20 PM
  5. Card deck arrays?
    By linc186 in forum New To Java
    Replies: 2
    Last Post: 03-16-2011, 09:56 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
  •