Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Java (https://www.askmehelpdesk.com/forumdisplay.php?f=440)
-   -   Java? (https://www.askmehelpdesk.com/showthread.php?t=299808)

  • Jan 6, 2009, 07:27 AM
    ClayREZ
    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
  • Jan 7, 2009, 10:18 AM
    jstrike
    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.

  • All times are GMT -7. The time now is 07:57 AM.