Question: Hello. I'm trying to write a java card program. I'm having trouble with the other section. Here is the outline for the java program. This

Hello. I'm trying to write a java card program. I'm having trouble 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 (represented by the array).

In the current hand, the player and computer cannot get the same card (that wouldnt be a proper deck

of cards).

To choose a card for each player, randomly choose a card in the deck 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 (see below).

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 display this

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 cards into two hands

}

}

/*

String[] arr = {"Ace of Spades", "King of Spades", "Queen of Spades", "Jack of Spades", "10 of Spades", "9 of Spades",

"8 of Spades", "7 of Spades", "6 of Spades", "5 of Spades", "4 of Spades", "3 of Spades", "2 of Spades",

"Ace of Clubs", "King of Clubs", "Queen of Clubs", "Jack of Clubs", "10 of Clubs", "9 of Clubs", "8 of Clubs", "7 of Clubs",

"6 of Clubs", "5 of Clubs", "4 of Clubs", "3 of Clubs", "2 of Clubs", "Ace of Hearts", "King of Hearts", "Queen of Hearts",

"Jack of Hearts", "10 of Hearts", "9 of Hearts", "8 of Hearts", "7 of Hearts", "6 of Hearts", "5 of Hearts",

"4 of Hearts", "3 of Hearts", "2 of Hearts", "Ace of Diamonds", "King of Diamonds", "Queen of Diamonds",

"Jack of Diamonds", "10 of Diamonds", "9 of Diamonds", "8 of Diamonds",

"7 of Diamonds", "6 of Diamonds", "5 of Diamonds", "4 of Diamonds", "3 of Diamonds", "2 of Diamonds"};

*/

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!