Hello M Trying Write Java Card Program M Trouble Section Outline Java Program Game Recreat Q43886259
Hello. I’m trying to write a java card program. I’m havingtrouble with the other section.
Here is the outline for the java program.
This game will recreate the simple game of War.
Assume there is only one deck in the deck of cards (representedby the array).
In the current hand, the player and computer cannot get the samecard (that wouldn’t be a proper deck
of cards).
To choose a card for each player, randomly choose a card in thedeck that has not already been used.
When a card is played, it cannot be played again.
The program ends when all 52 cards have been played.
The winner of each hand should be shown
Aces are high in our game
The total number of wins and ties should be shown (seebelow).
Here is an example output:
The Computer is showing a 9 of Spades
You are showing a 10 of Spades
You win!
The Computer is showing a 6 of Hearts
You are showing a King of Diamonds
You win!
At the end of the program, it should displaythis
Number of ties: 1
Computer wins 8 times
Player wins 17 times
Here is my code so far. I’m supposed to use only 1D arrays
public class SimpleWar
{
public static void main(String[] args)
{
String[] SUITS = {
“Clubs”,”Diamonds”, “Hearts”, “Spades”
};
String[] RANKS = {
“2”, “3”, “4”,”5″, “6”, “7”, “8”, “9”, “10”,
“Jack”, “Queen”,”King”, “Ace”
};
// initialize deck
int n = SUITS.length * RANKS.length;
String[] deck = new String[n];
for (int i = 0; i < RANKS.length;i++) {
for (int j = 0;j < SUITS.length; j++) {
deck[SUITS.length*i+ j] = RANKS[i] + ” of ” + SUITS[j];
}
}
// shuffle
for (int i = 0; i < n; i++) {
int r = i +(int) (Math.random() * (n-i));
String temp =deck[r];
deck[r] =deck[i];
deck[i] =temp;
}
//Shuffle into two list?
//having trouble shuffling the 52 cardsinto two hands
}
}
/*
String[] arr = {“Ace of Spades”, “Kingof Spades”, “Queen of Spades”, “Jack of Spades”, “10 of Spades”, “9of Spades”,
“8 of Spades”, “7 of Spades”, “6 ofSpades”, “5 of Spades”, “4 of Spades”, “3 of Spades”, “2 ofSpades”,
“Ace of Clubs”, “King of Clubs”, “Queenof Clubs”, “Jack of Clubs”, “10 of Clubs”, “9 of Clubs”, “8 ofClubs”, “7 of Clubs”,
“6 of Clubs”, “5 of Clubs”, “4 ofClubs”, “3 of Clubs”, “2 of Clubs”, “Ace of Hearts”, “King ofHearts”, “Queen of Hearts”,
“Jack of Hearts”, “10 of Hearts”, “9 ofHearts”, “8 of Hearts”, “7 of Hearts”, “6 of Hearts”, “5 ofHearts”,
“4 of Hearts”, “3 of Hearts”, “2 ofHearts”, “Ace of Diamonds”, “King of Diamonds”, “Queen ofDiamonds”,
“Jack of Diamonds”, “10 of Diamonds”, “9of Diamonds”, “8 of Diamonds”,
“7 of Diamonds”, “6 of Diamonds”, “5 ofDiamonds”, “4 of Diamonds”, “3 of Diamonds”, “2 of Diamonds”};
*/
Expert Answer
Answer to Hello. I’m trying to write a java card program. I’m having trouble with the other section. Here is the outline for the j…
OR