Results 1 to 2 of 2
  1. #1
    Member ps2cho's Avatar
    Join Date
    Oct 2004
    Location
    Socal, no hella here

    Java objects and methods....

    I am really struggling with these projects that are to do with creating objects and methods...

    Design and implement a class called Card that represents a standard playing card. Each card has a suit and a face value. Create a program that deals 20 random cards.

    Now i think im starting to get lost here...I have attempted below...but i think im doing this the wrong way...

    Is there a better way to do this? Can somebody steeeeeeer me in the right direction?

    (its not complete, but you can see where im heading...i think its wrong)

    Code:
    import cs1.Keyboard;
    import java.util.Random;
    import java.lang.Math;
    
    
    // card class which creates the card objects. It creates the suits(Hearts
    // Diamonds, Clubs and Spades and
    // the face values. 1-13
    class Card
           {
                   private int cardNumber;
                   private int cardNumberValue;
                   private String cardSuitValue;
                   private String cardFace;
    
                   // creates the card objects
                   public static void main(String[] args)
                   {
                           card = new card();
                   }
    
                   //Creates the cardNumber's and returns it.
                   public int getNum()
                   {
                           cardNum = Math.Random(1) +13;
                           return cardNum;
                   }
    
                   //assigns each cards number to a string with the proper name
                   public String getNumValue()
                   {
                           if (cardNum == 11)
                                   cardNum == "Jack";
                           if (cardNum == 12)
                                   cardNum == "Queen";
                           if (cardNum == 13)
                                   cardNum == "King";
    
                           cardNum == cardNumber;
    
                           return cardNumber;
                   }
           }
    
    public class P4_6
    
    {
           public static void main (String[] args) extends Card
    
           {
    			System.out.println("You got: " +card.getNumber);
           }
    }
    Main: i5-2500k @ 4.2GHz:.:P8Z77-V LE Plus Mobo:.:8GB DDR3 RAM:.:AMD 7870 2GB GPU:.:Corsair H50:.:Corsair 520HX PSU
    Laptop: Dell XPS12 Ultrabook
    Media Server: A6-5400k // ASRock FM2A75 Pro4-M // 4GB DDR3 // 60" Vizio LED 1080p
    HDD Server: Celeron 1840 // ASRock Z97Extreme4 // 6TB HDD's // Windows Server 2012


  2. #2
    Member BLcK's Avatar
    Join Date
    Aug 2005
    Location
    Ca, Los Angles
    Quote Originally Posted by ps2cho
    I am really struggling with these projects that are to do with creating objects and methods...

    Design and implement a class called Card that represents a standard playing card. Each card has a suit and a face value. Create a program that deals 20 random cards.

    Now i think im starting to get lost here...I have attempted below...but i think im doing this the wrong way...

    Is there a better way to do this? Can somebody steeeeeeer me in the right direction?

    (its not complete, but you can see where im heading...i think its wrong)

    Code:
    import cs1.Keyboard;
    import java.util.Random;
    import java.lang.Math;
    
    
    // card class which creates the card objects. It creates the suits(Hearts
    // Diamonds, Clubs and Spades and
    // the face values. 1-13
    class Card
           {
                   private int cardNumber;
                   private int cardNumberValue;
                   private String cardSuitValue;
                   private String cardFace;
    
                   // creates the card objects
                   public static void main(String[] args)
                   {
                           card = new card();
                   }
    
                   //Creates the cardNumber's and returns it.
                   public int getNum()
                   {
                           cardNum = Math.Random(1) +13;
                           return cardNum;
                   }
    
                   //assigns each cards number to a string with the proper name
                   public String getNumValue()
                   {
                           if (cardNum == 11)
                                   cardNum == "Jack";
                           if (cardNum == 12)
                                   cardNum == "Queen";
                           if (cardNum == 13)
                                   cardNum == "King";
    
                           cardNum == cardNumber;
    
                           return cardNumber;
                   }
           }
    
    public class P4_6
    
    {
           public static void main (String[] args) extends Card
    
           {
    			System.out.println("You got: " +card.getNumber);
           }
    }

    you should have main running a loop to create the cards and a seperate Card class. You should look into what constructors do.
    E6300 C2D..................Q6700
    Intel DG965WH............Intel DG33TL
    2X512MB PC2-4300 .....Mushkin 2X1GB PC2-6400
    ATI X1600 Pro..............EVGA 8800GT SC
    P180B.........................NSK-3480
    F@H-=FOLD @ HOME=- User name: BLcK : Team#32

Posting Permissions

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