Ask Experts Questions for FREE Help !
Ask
    ClayREZ's Avatar
    ClayREZ Posts: 2, Reputation: 1
    New Member
     
    #1

    Jan 6, 2009, 07:27 AM
    Java?
    The problem is:

    "Design a class whose instance stands for one pack of cards and an other class whose instance stands for one card. Your program choose two cards randomly and output the result of comparison of the chosen cards. The suits order is spade >heart > diamond > club. The comparison should consider suits first and then points.
    Hint: The method "public int nextInt(int n)" in "java.util.Random" can be used to get an random integer number r between 0 and n.(0 <= r < n) ".

    I'M HOPING SOMEBODY CAN HELP ME WITH THIS.I'M A NEWBIE TO THE JAVA COURSE I'M TAKING.I WOULD REALLY APPRECIATE IT,PLEASE.:(:confused::o
    jstrike's Avatar
    jstrike Posts: 418, Reputation: 44
    Full Member
     
    #2

    Jan 7, 2009, 10:18 AM
    Normally I don't help with homework but since you didn't ask for the code like most people do, here's how I would architect this:

    Define a base class that has two arrays, one for the card number and one for the suit.
    I would do it something like this:
    protected static final String[] cardNumber = {"2","3"... "J","Q","K","A"};
    Do the same thing for the suit. The order that you define the array in is important.
    Note: It would be better to use an enumerated class instead of the string arrays but this is probably easier for beginners.

    Create another class called Card that extends the base class you just created. You'll have 2 int values in there with getters and setters. Those will be the index values for the cardNumber and cardSuite arrays. The constructor should take both int values as parameters.

    Create another class called Deck and extend the base class. You'll have a list object in here that holds the deck of cards and a method that will take an int as a parameter and return one of the cards from the list object. The constructor should create the 52 Card objects necessary.

    You'll then have another class with the main method in it that will instantiate Deck, pull the cards at random and compare them based on the rules given to you. Technically you should create a method in the Card class that takes another Card as a parameter and returns a value to tell if it's higher or lower.

    If you have problems post the code and we'll do what we can to help.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Java [ 4 Answers ]

We can not instantiate an abstract class. But we can write a constructor in abstract class. If we are not able to create an object, then how and why is it possible to create a constructor in an abstract class?

Why java? [ 2 Answers ]

I saw java is very popular language so I want know lot of information about java

Java [ 2 Answers ]

Hey guys, I heard a rumor that Microsoft wasn't going to support Java by the year 2008. Has anyone else heard this? If so, do you know what effect, if any, this willhave on Java programming. What I mean is will Java be phased out or is there a lot more uses for Java. I don't know that much about it...

Java 2 sdk [ 3 Answers ]

I went to the java.sun.com website to download Java 2 SDK. I selected to save it to my desktop and when it finishes downloading the icon on the desktop is one of those that ask you what program to open it with. I have downloaded like 3 different things and they all do the same thing (the white...

By using vc++ or java? [ 1 Answers ]

Hi, I want to make image processing application.which programming language I should use? Either vc++ or java or anything else? Please guide me early.


View more questions Search