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);
       }
}

__________________
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: AMD BE-2300 // 6TB HDD's and stuff

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 04:47 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, 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?