Amazon Interview Question
Software Engineer / DevelopersCountry: United States
Interview Type: Phone Interview
the explanation for cardleft() should be there.
and another function returncard(Card c) is missing.
As, deck is holding the list of cards, the card class details are to be added like
Class Card{
private int suite;
private int num;
public Card(int suite, int num){
this.suite=suite; this.num=num;
}
}
for the poker or card game:-
- shishirvicto November 03, 2011we have to make such decision,
for deck part():_
1.deck is shuffled
2.card are dealt one at a time from the deck and added to the player's hand
for card parts:-
1.cards can be removed from hands
2.new card can be added
so basically it comes in our mind that class would be
game,
player,
hands,
card,
deck,
value and
suit
now here i am going to explain how to design some class according to our analytical knowledge;
let i am going to design class for say deck class and hands
for deck class :- the question comes whether it is shuffled or whether its dealt.
so here ,obviously method would be shuffle() and dealcard()
we will think for hands in same fashion.
that is for hands class ,we have to think about card is added or removed.
so clearly here method becomes addcard() and removecard()
now here when we are dealing with remove card then the question comes,how we are going to remove or add from deck of cards.
and according to our analytics we will have to add cardleft() type method for deck class
so it would be like
class deck{
private:
int a[52];
.....
.....
public:
shuffle();
dealcard();
cardleft();
}
and for hands class
class hand{
private:
.........
........
public:
addcards();
getcardcount();
rearrange();
removecard();
discard();
}
blah bla......