Respuesta :
You are working for an online gaming company. You have been asked to write some code to support online card games, such as poker, gin rummy, other games. Below is the code structure
What is code?
The set of instructions or set of rules written in a specific programming language are referred to as "computer code" in computer programming (i.e., the source code).
Additionally, it refers to the source code that has undergone compilation and is now prepared for computer execution (i.e., the object code).
Below is the code structure
Code:
package com.test.Chegg;
import java.util.Arrays;
import java.util.Random;
public class CardGame {
static int DECK_LENGTH = 10;
static int CARD_PER_VALUE = 4;
static int PLAYER_COUNT = 4;
static int HAND_SIZE = 5;
static int[] deck = new int[DECK_LENGTH];
static int[][] playerHands = new int[PLAYER_COUNT][HAND_SIZE];
public static void main(String[] args) {
Arrays.fill(deck, CARD_PER_VALUE);// initializing deck with CARD_PER_VALUE
// filling playerHands with Random card picked
for (int i = 0; i < PLAYER_COUNT; i++) {
for (int j = 0; j < HAND_SIZE; j++) {
int randomCardValue = getRandom();
playerHands[i][j] = randomCardValue;
}
}
// printing the hands for each player
for (int i = 0; i < PLAYER_COUNT; i++) {
System.out.print("Player " + (i + 1) + " hand : ");
for (int j = 0; j < HAND_SIZE; j++) {
System.out.print(playerHands[i][j] + " ");
}
System.out.println("");
}
// printing the remaining cards
System.out.println("");
System.out.println("Cards Remaining:");
System.out.print("Card: ");
for (int i = 0; i < DECK_LENGTH; i++) {
System.out.print(i + " ");
}
System.out.println("");
System.out.print("Count: ");
for (int i = 0; i < DECK_LENGTH; i++) {
System.out.print(deck[i] + " ");
}
}
// function to select random card fro available cards
private static int getRandom() {
// TODO Auto-generated method stub
int randomCardValue = 0;
for (int i = 0; i < DECK_LENGTH; i++) {
Random random = new Random();
randomCardValue = random.nextInt(DECK_LENGTH);
if (deck[randomCardValue] == 0) {
continue;
} else {
deck[randomCardValue]--;
break;
}
}
return randomCardValue;
}
}
Learn more about code
https://brainly.com/question/26134656
#SPJ4