Your deck of cards is based on a boolean array of size 52. Truemeans a card is
Question:
Your deck of cards is based on a boolean array of size 52. Truemeans a card is still in the deck, false means it is not. The indexnumbers of the boolean array will be used to convert that number toits corresponding card. It will be up to you to determine how theconversion is done, but each index should map to a specificoutput.
For example, the number 4, which is index 4 of the array, couldmap to the String value “4D”. Just make sure that the number 4always maps to “4D”.
Depending on how you do the conversion will determine whatnumbers to convert to what cards. I have provided two String arraysat the top of the assignment you may use in your conversions. Theyare visible to the entire program, but only should be used inconvertCard(int card).
The players are represented by a 2D array of Strings. The totalnumber of players is user specified. Each row will represent oneplayer, and the columns associated with that row will their cards.The total number of players allowed will be from 2 to 8.
-------------------------------------------------
Below is a sample run.
How many people are playing? 2
Player 1 hand: 7D 2D 2C 5D 4D
Player 2 hand: 10H 8H 9H AS 2H
Would you like to deal again? (Type "no" to quit.) yes
How many people are playing? -1
Please re-enter a number between 2 and 8.
How many people are playing? 5
Player 1 hand: 4C AH 8D AS 9C
Player 2 hand: 9H 8S JH 6S 6H
Player 3 hand: AD 3S 2D 2H 5D
Player 4 hand: 9D AC 7C KS JC
Player 5 hand: 7H 2C 10C 3H 10D
Would you like to deal again? (Type "no" to quit.) yes
How many people are playing? 999
Please re-enter a number between 2 and 8. How many people areplaying? 8
Player 1 hand: QD 7H 5S JC 4S
Player 2 hand: 3H 2C 6S QH 7C
Player 3 hand: KH 3D JS 6C 10S
Player 4 hand: 2D AS 2S 5H 9S
Player 5 hand: JD AC 4C 8D JH
Player 6 hand: 10H QC 4D KC AH
Player 7 hand: 8S 10C 6D 9C 7S
Player 8 hand: 5D QS AD 5C KS
Would you like to deal again? (Type "no" to quit.) no
Thank you, goodbye
-----------------------------------------------
This is what I have so far. I have finished some of themethods, however, the methods that I commented "TODO" in are notfinished. These are the methods that I could not figure out how todo.
There are also comments that instruct you on how whatthe method should do.
import java.util.Scanner;
public class CardGame {
//class level variables you may use toconvert numbers from 0-51 to a card.
public static finalString[] cardNumbers ={"2","3","4","5","6","7","8","9","10","J","Q","K","A"};
public static finalString[] cardSuits ={"D","H","C","S"};
public static void main(String[] args) {
Scanner scr = newScanner(System.in);
//Your deck of cards.
//True means the card isstill in the deck, false means it has been dealt
boolean[] deck = newboolean[52];
//A 2D array that holdsStrings.
//The first perameter willdetermine the number of players.
//The second perameterwill determine how many cards they will hold. It shouldalways be 5.
String[][] players;
//boolean variable used todetermine if the user would like to play again.
boolean playAgain;
do{
players= playerPrompt(scr); //create and store the 2D array
resetDeck(deck); //reset the deck so all cards are present
dealHands(players, deck); //deal out cards toeach player
displayHands(players); //show each players hands
playAgain = playerRePrompt(scr); //see if the player wishes to play again
} while (playAgain);
System.out.println("Thank you,goodbye");
scr.close();
}
/**
* Ask the user how many players they want toplay.
* Make sure the number entered is between 2and 8.
* A player can only hold 5 cards at atime.
* Return a new 2D String containing thetotal players and the amount of cards they can hold.
* ie. new String[totalPlayers][5];
*
* @param Scannerscr
* @return String[][]
*/
public static String[][] playerPrompt(Scanner scr)
{
//TODO
}
/**
* Ask the player if they want to playagain.
* Return true if they want to play again,false otherwise.
* The only way to quit is by entering"no".
*
* @param Scannerscr
* @return boolean
*/
public static boolean playerRePrompt (Scannerscr)
{
//TODO
}
/**
* Reset the deck for the next round.
* Think of this as collecting all thecards.
* A card is in the deck if it's value istrue.
*
* @param boolean[] deck
*/
public static void resetDeck(boolean[]deck)
{
//TODO
}
/**
* Deal out the cards to each player.
* The 2D String array called players willhold the card values.
* See the assignment description for avisual of how this will work.
* You will need to call dealCard and use adouble for loop to fill the 2D String array.
*
* @param players
* @param deck
*/
public static void dealHands(String[][]players, boolean[] deck)
{
//int i =players.length;
//String set =CardGame.dealCard(deck);
//int j =Integer.parseInt(set);
//players = newString[i][j];
for (int i=0;i
{
for(int j=0; j<5; j++)
{
players[i][j]= dealCard(deck); //new String[i][j];
}
}
}
/**
* Deal one card from the deck.
* Use the boolean array to tell if a cardhas been dealt yet.
* You will need to call convertCard toconvert the index of an available card to it's correct cardrepresentation.
* You will need to use a random numbergenerator to simulate an actual shuffled deck.
* Remember, Math.random() returns a numberfrom 0 to .99999....
*
* @param deck
* @return String
*/
public static String dealCard(boolean[]deck)
{
//TODO
}
/**
* Given a number between 0 and 51, convertthat number to the correct format.
* It is up to you how each card isconverted, just make sure that each number is mapped to a uniquecard.
* Just make sure a mapping is 1 to 1,meaning if 4 converts to "4C", it will always convert to "4C"
* Also make sure it is possible for eachcard to be dealt.
*
* I have provided two arrays at the top,cardNumbers and cardSuits you may use if you wish.
* There is clever way to convert a numberusing modulus and division, and this method can be done in oneline.
*
* @param card
* @return Stringrepresenting a card in correct format
*/
public static String convertCard(intcard)
{
String numbers= cardNumbers[card%13];
String suits= cardSuits[card/13];
return numbers +suits;
}
/**
* Display all the players hands to theconsole.
* You will need a double for loop.
*
* @param players
*/
public static void displayHands(String[][]players)
{
for(int i = 0;i
{
for(intj = 0; j<5; j++)
{
System.out.println("Player" + i +"hand: " + j);
}
}
}
}
Basic Business Statistics Concepts And Applications
ISBN: 9780132168380
12th Edition
Authors: Mark L. Berenson, David M. Levine, Timothy C. Krehbiel