Skip to content

Instantly share code, notes, and snippets.

@nastajus
Created November 28, 2014 03:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nastajus/75117b5e51e3607bc6fb to your computer and use it in GitHub Desktop.
Save nastajus/75117b5e51e3607bc6fb to your computer and use it in GitHub Desktop.
interview question from IBM staff: create the signatures, access specifiers, for general card game. It needs to have a deck, be shuffleable, and track the deck separately from cards on table. There are no players in this version of this simple API.
C#
class Card {
public static enum CardType { “HEART”, “SPADE”, “DIAMOND”, “CLUB” }
public CardType type;
public int num;
//said I wanted to use properties with backing fields to limit access to sets,
//only provide public gets, but that I wasn’t exactly sure how to do it
public Card( int type, int num ){
this.type = (CardType)type;
this.num = num + 1;
}
}
class Deck {
List<Card> deck = new List<Card>();
List<Card> drawn = new List<Card>();
public Deck(){
for( int i = 0; i < 13 ){
for ( int j = 0; j < 4 ) {
desk.Add( new Card( i,j ) );
}
}
Shuffle();
}
public Shulffle(List<Card> from, List<Card> to){
//temp list
//randomly select a card from range 0 to size remaining of deck and
//move to temp list
//
}
public Card Draw(){
if ( deck.size > 0 ) {
Card last = deck.last();
deck.remove(deck.last());
return last;
}
else
return null;
//upon discuss I raised returning null isn’t best practice
//but didn’t have better alternative.
}
}
class Tester{
Deck deck = new Deck();
deck.Shuffle();
Card deck.Draw();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment