0

I am supposed to do a project where I declare and instantiate 5 empty card slots called myHand using arrays, and I will need an advanced mutator method that sets a single card into the hand, and an advanced accessor that gets a card from myHand. Does the following code work for all of above? Please know that Card is from another class called Card.java where all card values, suits, etc. are completed

private Card[] myHand;
private int numberHand;  //counts number of card in hand
private int numberDealt; //counts number of cards dealt onto the table

public void setCard(int I, Card c)
{
    myHand[I]=c;
    numberHand++;
}

public Card getCard()
{
   Card tempCard = myHand[numberDealt];
   numberDealt++;
   return tempCard;
}
Edward
  • 5
  • 3
  • Without seeing your homework it's not possible to determine if your code does what it's supposed to. – nicomp Apr 18 '20 at 01:45
  • If the `get()` method does take an `int` parameter, why would the `set()` method do that? Don't you think the `set()` method should use the `numberHand` for the array index, similar to how `get()` uses `numberDealt` for the array index? – Andreas Apr 18 '20 at 01:55

0 Answers0