Question:

How to do this task using Java Programming?

by  |  earlier

0 LIKES UnLike

Design, implement and test a program to represent a pack of cards as an array of integers; the array should hold the values 1 to 52 to represent each of the individual cards; 1 to 13 for Hearts, 14 to 27 Clubs and so on.

The following methods should be developed:

- A method to output the value of the card given an integer; that is something like 4 Hearts or King of Spades

- A method to shuffle the cards

- A method to deal a number of cards from a pack

- Any other methods that you choose to add.

 Tags:

   Report

2 ANSWERS


  1. This looks suspiciously like a homework question.

    It's certainly not a trivial task.

    Start it off and ask again if you get stuck!

    Regards

    G  


  2. Won't write your homework for you, but will give you a few hints.

    The 'deck' itself will be an integer array of 52, obviously.

    Changing a numeric value to a string equivalent sounds like a job for 2 enum structures and some modulus division.

    Dealing would simply be stepping thru the deck array.

    Shuffle is the tricky part...easiest way to do this is with a 'unshuffled' and 'shuffled' deck array.

    1) Initialize the shuffled array to zeroes

    2) Seed your randomize function

    3) For i 0->51

    a) Randomize for value j between 0 and 51-i

    b) Move unshuffled(j) to shuffled(i)

    c) For k j->51-i move unshuffled(k) to unshuffled(k-1)

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.