Amazon Interview Question
Software Engineer / Developerscould you please code the functions
public void createCard(int number, int type);
public static int drawCard();
public static void shuffle();
One class for cards, which accepts Suit and Rank of the card. It should have a constructor that accepts Suit and Rank, and a copy ctor, assignment operator. That is a minimal interface for a card.
Now, another class that contains a vector of cards. I would have a static int in there for the number of cards (54?). Add construct/dtor functions. Add a reset function to sort the cards to their original order. Add a function that accepts a number and deals the topmost cards of the deck. It should remove them from the deck. Add another function to shuffle the cards... And the list goes on.
Create a class called Cards
- Anonymous January 10, 2009public class Cards{
public int number; // 1-Ace... 11-, 12 Queen, 13-King
public int type; 1-4 is each type
public void createCard(int number, int type);
public static int drawCard();
public static void shuffle();
public static void main(String[] args){
Cards deck = new Cards[52];
int k=0;
for(int i=0;i<4;i++){
for(int j = 0;j<13;j++){
deck[k++].create(j,i);
}
}
Cards.shuffle();
}