473,807 Members | 2,884 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cards deck problem

Can any one help me with this im not getting it even after reading
books because there is not much of discussion anywhere

a>
Implement a calss that represents a playing card. The class should
implement the following methods:
_ _ init _ _ (self, rank, suit) Creates a card.
rank is an integer in range of 1 to 13 (Ace:1, King 13), suit is a
character in set {'h','d','c','s '}
getRank(self) Returns the rank of the card
getSuit(self) Returns the suit of the card
BJValue(self) Returns the 'Blackjack Value' of the card (Ace:1, Face
card:10)
_ _ str _ _ (self) Returns a string naming the card. For example: 'Ace
of Spades'

Test your class by writing a 'test harness' that generates 'n' randomly
generated cards, where 'n' is supplied by the user. Print out the
string associated with each card and it's 'Blackjack value'
b>
Extend the card class to display in a graphics window. the new class
should support the following method: draw(self, win, center) Draws a
card in a window.
Use the extended class to display a hand of five random cards.
cWrite a program that creates a list of card objects as above and
print out the cards grouped by suit and in rank order in each suit.
the program should read the values for the list of cards from a file,
where each line in the file specifies a single card with the rank and
then the suit separated by a space. Hint: sort the list first by rank,
and then by suit.
dCreate a new class deck that represents a pack of 52 cards. Which
supports the following methods:

_ _init_ _ (self) - Creates a deck of cards in standard order.
shuffle(self) - Randomizes the order of the cards
dealCard(self) - Returns a single card from the top of the deck, and
removes the card from the deck.
cardsLeft(self) - Returns the number of cards left in the deck.
Test your class by having it deal out a sequence of 'n' cards where 'n'
is a number input by the user. The program should either print out the
cards, or display them in a window.

Your urgent and quick reply help will be appreciated the most.

Arun Nair

Oct 26 '06
10 4968
Gabriel Genellina <ga******@yahoo .com.arwrites:
At Friday 27/10/2006 00:48, Michael Naunton wrote:
As noted in the problem, a deck has 52 cards. cardsLeft(self)
therefore always returns 52.

Uhm, maybe it's a matter of language, but how do you name the pile of
cards remaining to be dealt once the game begins?
In English? I'd call that a deck. However, that deck doesn't contain
52 cards any more, so a thing that behaves that way doesn't fit the
definition of "deck" in the problem.

Perhaps a better definition would have used language like "... begins
with 52 cards" or the like, and described the properties of a deck to
be modelled.

Is this merely pedantic? If we were describing the rules of a game to
be played by humans, yes. But in this case we're describing parameters
of a problem to be modelled in a computer, hopefully independently by
each student in a class. Getting the problem defined precisely is
essential, otherwise judging the result fairly is impossible.

(good sigmonster, have a cookie)

--
\ "We demand rigidly defined areas of doubt and uncertainty!" -- |
`\ Vroomfondel, _The Hitch-Hiker's Guide To The Galaxy_, Douglas |
_o__) Adams |
Ben Finney

Oct 28 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
1975
by: Radith | last post by:
Hi All, I have got this task which I cant get my head around: It asks how I would store information: I just want to get an opinion from the group: So here's the question: " You have been asked to write a program for a card playing friend. How would you store information about playing cards? For example how would
6
6224
by: CaseyB | last post by:
If I wanted to create a game like Solitaire that would first randomly shuffle a deck of cards, I figured out that all I had to use is the Random() class or rnd and make sure I use the Randomize function so as not to get the same card twice. BUT I noticed that some Solitaire games allow you to select one of the 4,294,967,296 possibilities in a 52 card deck. I want to do something similar, after I shuffle the deck I want to show the number...
11
7540
by: prince99 | last post by:
i am worlking on the cards class so it can do several things. My code is as before but need to change the things to solve given problem Create a new class Deck that represents a pack of 52 cards. The class should support the following methods: __init__ ( self ) Creates a deck of cards in standard order. shuffle(self) Randomizes the order of the cards. dealCard(self) Returns a single card from the top of the deck, and removes the card...
4
9195
by: Pratik | last post by:
For the time being, I'm doing a simple swap method for my deck of cards using the random number generator in cstdlib. I've created a dynamic array of a type class Card. When I go to shuffle it and then later print the shuffled deck, some of the values overlap -- I can't figure out why. Here's my code: void shuffle() { for (counter = 0; counter < 120; counter++) {
11
14157
by: cazconv2007 | last post by:
hi i have homework due tomorrow been trying to do java homework all week and nothings happening really starting to stress out i dont understand what the program is meant to do or how to use three classes The program This week you are going to write three classes: Card.java, Deck.java and DeckTester.java. The specification for each class is given below. Card.Java This is a simple class that represents a playing card.
3
3062
by: JayP | last post by:
I'm trying to shuffle a deck of card in C ++, with out having the same card twice. And I'm supposed to give each player 5 cards. And if they want, they can replace 3 cards. Right now I can assign 5 cards to each player, but some of the cards repeat themselces (ex. I have 3 Ace of spades, or 2 king of clubs, etc). Can anyone help me fix this problem. Here is what I have so far. #include <iostream> #include <ctime> #include <cstdlib>...
8
29172
by: garyrowell | last post by:
I have been at this programme for hours trying to work out what is wrong. Any help would be very much appricated. Here is the breif I received. The program This week you are going to write three classes: Card.java, Deck.java and DeckTester.java. The specification for each class is given below. Card.Java This is a simple class that represents a playing card. Card has two attributes: • rank which is a String that represents the value...
1
2393
by: Vneha | last post by:
import java.util.*; public class Deck { public static int numSuits = 4; public static int numRanks = 13; public static int numCards = numSuits * numRanks; private Card cards;
0
9720
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9599
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10374
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7650
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5685
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4330
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3011
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.