Notices

Overclockers Forums > Software > Programming Tips and Tricks
Programming Tips and Tricks
Forum Jump

Java objects and methods....

Post Reply New Thread Subscribe Search this Thread
 
 
Thread Tools
Old 11-30-05, 06:40 PM Thread Starter   #1
ps2cho
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);
       }
}

__________________
Q6600 @ 3.6GHz:.:GA-P35-DS3L:.:4GB DDR2 RAM:.:BFG GTX 260:.:Ultra 120 eXtreme:.:Corsair 520HX
X2 3600+ @ 3.1GHz:.:GA-MA78GPM-DS2H:.:1GB DDR2 RAM:.:eVGA 7900GS 256MB:.:Corsair 400CX
HTPC: X4 620 0.9v:.:DFI LP JR 790GX:.:2GB DDR2 RAM:.:Asus HD4550 512MB:.:Corsair 450VX:.:32" Vizio 1080p HDTV

Laptop: Sony Vaio CW27FX:.:Intel Core i5 @ 2.4GHz:.:GT 330M 512MB:.:4GB DDR3 RAM:.:14" LED

AMD CPU List:.:How to HLDS:.:Heatware
"The constant assertion of belief is an indication of fear."-Jiddu Krishnamurti

ps2cho is offline   QUOTE Thanks
Old 11-30-05, 07:19 PM   #2
BLcK
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
BLcK is offline   QUOTE Thanks

Post Reply New Thread Subscribe


Overclockers Forums > Software > Programming Tips and Tricks
Programming Tips and Tricks
Forum Jump

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Mobile Skin
All times are GMT -5. The time now is 05:04 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
You can add these icons by updating your profile information to include your Heatware ID, Benching Profile ID or your Folding/SETI profile ID. Edit your profile!
X

Welcome to Overclockers.com

Create your username to jump into the discussion!

New members like you have made this the best community on the Internet since 1998!


(4 digit year)

Why Join Us?

  • Share experience
  • Max out your hardware
  • Best forum members anywhere
  • Customized forum experience

Already a member?