Question

package cards; import java.util.ArrayList; import java.util.Scanner; public class GamePlay { static int counter = 0; private...

package cards;
import java.util.ArrayList;

import java.util.Scanner;
public class GamePlay {

static int counter = 0;
private static int cardNumber[] = {1,2,3,4,5,6,7,8,9,10,11,12,13};
private static char suitName[] = { 'c', 'd', 'h', 's' };

public static void main(String[] args) throws CardException, DeckException, HandException
{
Scanner kb = new Scanner(System.in);

System.out.println("How many Players? ");
int numHands = kb.nextInt();

int cards = 0;
if (numHands > 0) {
cards = 52 / numHands;
System.out.println("Each player gets " + cards + " cards\n");
} else {
System.out.println("OOPS you entered an invalid number try again! ");
}
Hand hand;
Card c;

ArrayList<Hand> hands = new ArrayList<Hand>();
for (int i = 0; i < numHands; i++) {
hand = new Hand(cards);

for (int j = 0; j < cards; j++) {
c = getANewCard();
hand.getCard(c);
}
hands.add(hand);
}
play(hands);
}
private static void play(ArrayList<Hand> hands) throws CardException, HandException
{
Card hand = new Card(1, 'd');
int i = 0;
int playerNum = 0;

while (i < hands.size() * hands.get(0).handSize)
{
playerNum = i % hands.size();
hand = hands.get(playerNum).giveCard();
System.out.println("Player " + (playerNum + 1) + " plays the "
+ hand.toString());

if(hand.getCardName().equals("Ace")){
System.out.println("Player " + (playerNum + 1 ) + " wins! ");
break;
}
i++;
} }
public static Card getANewCard() throws CardException
{
counter++;
return new Card(cardNumber[counter%13], suitName[counter%4]);
}
}

In this file of code i was wondering why there are certain things in place.

static int counter = 0;
private static int cardNumber[] = {1,2,3,4,5,6,7,8,9,10,11,12,13};
private static char suitName[] = { 'c', 'd', 'h', 's' };

What is the use of declaring these lines of code?

Then what does this line of code do in this program?

public static Card getANewCard() throws CardException
{
counter++;
return new Card(cardNumber[counter%13], suitName[counter%4]);
}

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
package cards; import java.util.ArrayList; import java.util.Scanner; public class GamePlay { static int counter = 0; private...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT