Please design a deck of cards in Java
Dear Future Colleague:
I’ve been asked to perform a quick technical evaluation of your résumé before we ask you in for an interview. You obviously have the right kind of experience and I’m looking forward to meeting you soon.
We are asking all candidates to perform a little exercise before coming in for the first meeting. I realize you have a great deal of relevant experience, so this will not take very much of your time at all.
And I’m sure you appreciate the fact that we value ability and merit above certifications and other pieces of paper.Please design a deck of cards in Java
Imagine that we are writing a casino program. We are not going to write the whole program right now, just the part of the program that has to handle the decks of cards to be used by the rest of the program.
If you are not familiar with the kind of cards used in European card games (like Poker, Bridge, Blackjack, Crazy Eights, Rummy, and so on), please write back and I will give you a different problem. You should be comfortable with concepts like the ranks of the cards, the suits, shuffling, and dealing.
Your task is to design the interfaces and/or classes we would need for the deck(s) of cards. At a bare minimum, your classes should handle everything we need to know about decks of cards, the cards themselves, and operations on decks of cards like shuffling, dealing, removing cards from a deck (some games have one or two jokers, some don’t, some only use the cards from 9 and up, some from 7 and up, some use them all), and combining decks (
Canasta uses two, four, six, or more decks of cards with jokers!)
You do not need to worry about the mechanics of games like hands of cards, ranking Poker hands, knowing about Trumps or Bowers (as in Euchre and Bridge), discard piles (as in most games), or melds (as in Gin, Rummy, and Canasta). Imagine that other people will write all of that stuff using your classes for decks and cards.
Please be
specific about the interfaces, abstract classes, and concrete classes you will need. There is no need to actually write the bodies of methods, but please be specific about what the methods are called, what parameters they take, and what they return (if anything).
I am especially interested in the relationships between the classes. Although you don’t have to write out each method, if you expect that a method would call other methods in your design, please say so.
For example:
class Deck {
// calls Card.arrangeRelativeTo(Card othercard)
public void shuffle () { ... }
}
You can see that in this hypothetical design cards have some ability to arrange themselves relatively to each other and I am documenting that
Decks
can be shuffled and they use the
Card
s’
arrangeRelativeTo
method to do so. Obviously, you don’t need to follow that design. It’s just an example.
This extends to constructors. Does creating a
Deck
create
Card
s? Or does it use
Card
s that already exist? Or are
Card
s not even objects but are represented by primitive types?
About UML
You can just write out the skeleton of the classes and interfaces. If you prefer to use
UML, be my guest. As long as your design answers all of the questions I have, use whatever notation you prefer. Just don’t fall into the trap of letting the notation drive the design: just because a certain type of UML diagram doesn’t indicate the CREATES-A relationship, that doesn’t mean you shouldn’t add it: what’s important is the design, not the document.
Requirements?
Feel free to
email or call with any questions you might have about requirements. This is not meant as a test of your ability to read my mind about what I want or to ask insightful questions. So, it’s ok to ask me questions. If you have a choice to make, it’s also ok to just decide.
For example, you might wonder how to represent which cards are left in a deck after dealings some out. Should you use a standard OO pattern like a
List
or
Set
? That might be fine if our Casino program is a single-user game. But if we are running a web-based virtual casino with many thousands of users, performance might be important enough that we consider using something like a
bitfield for each deck.
If you want, you can ask what’s more important. Or you could just decide for yourself. Using a bitfield for performance is a fine decision. So is having a standard OO design. Each works well for a particular set of requirements.
So don’t be too concerned about asking a million questions. I just want to get a basic idea of your comfort level designing OO software.
Thanks,
Reg Braithwaitep.s. This isn’t a trick question. There’s no right answer, and as I said above I don’t even expect full implementations, so you don’t even have to write code that compiles.
There is absolutely no need for a bunch of stuff I didn’t ask about, like requirements in three-ring binders or JUnit test cases. I know that you are probably tempted to show off your depth of experience and SDLC knowledge, however I really only want to know how you would approach the design in this question.
Please save the other stuff for the interview. Just because I don’t need to know about it right now doesn’t mean I don’t agree that it’s important!
Labels: java, jobs