2 Replies - 2886 Views - Last Post: 22 November 2011 - 02:07 PM Rate Topic: -----

#1 jpb14  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 22-November 11

problem creating a deck of cards in java

Posted 22 November 2011 - 10:30 AM

im trying to create a deck of cards in java, but there must be a Card class with an array of suit and an array of value and a deck class which is able to shuffle and deal the cards etc. and im unsure if im creating the array properly. this is the code ive got so far. would anyone be able to show me where im going wrong

import java.util.*;
public class Card{
    private String Value;
    private String Suit;
    
    public Card (String Value, String Suit) {
        Value = Value;
        Suit = Suit;
    }

        public String getValue() {
        return Value;
    }
    
    public String toString() {
        String [] Suit = {"C", "S", "H", "D"};
        String [] Value = {"A", "2", "3", "4", "5", "6", "7", "8", "9",
                "T", "J", "Q", "K"};
                return Value+Suit;
    }

    
    }


This post has been edited by smohd: 22 November 2011 - 10:43 AM
Reason for edit:: Set font size to normal


Is This A Good Question/Topic? 0
  • +

Replies To: problem creating a deck of cards in java

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2728
  • View blog
  • Posts: 11,469
  • Joined: 20-September 08

Re: problem creating a deck of cards in java

Posted 22 November 2011 - 10:56 AM

Java variable names should being lower case. The arrays you have defined do nothing at the moment - what do you plan to use them for?
Consider using enum for the various ranked entities. There are examples of this for a Card class in the Oracle Java enum tutorial
Was This Post Helpful? 1
  • +
  • -

#3 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10573
  • View blog
  • Posts: 39,146
  • Joined: 27-December 08

Re: problem creating a deck of cards in java

Posted 22 November 2011 - 02:07 PM

At the very least if you do use String[] to represent the suits and values (the names should be plural as well to be descriptive), they should be globals or at least instance fields, rather than local variables that will keep being recreated each time toString() is called.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1