Answered step by step
Verified Expert Solution
Question
1 Approved Answer
GIVEN CODE FOR REFERENCE (MUST BE DONE IN JAVA) import java.util.*; class SomethingLikeWar { public static void main (String[] args) { String [] faces =
GIVEN CODE FOR REFERENCE (MUST BE DONE IN JAVA)
import java.util.*;
class SomethingLikeWar
{
public static void main (String[] args)
{
String [] faces = {" ", " ", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"};
\\ J, Q, K, AND A CAN BE DISPLAYED AS 11, 12, 13, AND 14 IF NEED BE.
int card = 11;
System.out.println(faces[card]);
}
}
Lab - Something Like War You are going to create a card game that plays kinda like the game of war. 1. You should begin by creating two arrays of size 26. One array to store player l's cards and a second to store player 2's cards. 2. Initialize each spot in each array to a random number 2-14, where 2 is a card with the value of 2, 3 a card with the value of 3, ... Il a card with the value of Jack, 12 Queen, 13 King, and 14 Ace. 3. Self-check: Print out a list of the cards for each player using a for-loop so that it prints something like: Player 1 has [11, 12, 14, 14, 3, 2, 4, 8, 910, ...) Player 2 has (12, 14, 13, 14, 2, 7,5, 3, 8, 12,...) We are printing the cards only so that we can check that the rest of the game plays correctly and that the spots were initialized correctly. At the end of the game, we will remove this, so that the user doesn't know what the card are as the beginning. 4. Cycle through the indices 0 - 25 and compare which player has a higher card value for each "hand" (index). You should keep a tally of how many 'hands' each player wins. For example, if we use the arrays above, in the first hand at the first index - index 0), player 2 would win the hand because he has a 12 when player 1 has a 11. For the showing hands, player I would score 4 hands, player 2 would score 5, and there would be l tie. Part of the pseudocode for this process could be: FOR Each Card in the Deck IF Player 1 has the higher card Increase player l's wins by 1 ELSE IF Player 2 has the higher card Increase player 2's wins by 1 ELSE IF There's a tie Increase number of ties by 1 ENDFOR 5. Print out how many wins each player has and how many ties were made. [E] Ask the user for the names of the two players and instead of displaying "Player 1" or "Player 2" throughout the program, use the player's names. [H] Allow ties to be broken by awarding the point for the tie to the player that wins the following hand. This means that the hand following a tie is worth 2 points instead of just one and a tie is worth nothing. Lab - Something Like War You are going to create a card game that plays kinda like the game of war. 1. You should begin by creating two arrays of size 26. One array to store player l's cards and a second to store player 2's cards. 2. Initialize each spot in each array to a random number 2-14, where 2 is a card with the value of 2, 3 a card with the value of 3, ... Il a card with the value of Jack, 12 Queen, 13 King, and 14 Ace. 3. Self-check: Print out a list of the cards for each player using a for-loop so that it prints something like: Player 1 has [11, 12, 14, 14, 3, 2, 4, 8, 910, ...) Player 2 has (12, 14, 13, 14, 2, 7,5, 3, 8, 12,...) We are printing the cards only so that we can check that the rest of the game plays correctly and that the spots were initialized correctly. At the end of the game, we will remove this, so that the user doesn't know what the card are as the beginning. 4. Cycle through the indices 0 - 25 and compare which player has a higher card value for each "hand" (index). You should keep a tally of how many 'hands' each player wins. For example, if we use the arrays above, in the first hand at the first index - index 0), player 2 would win the hand because he has a 12 when player 1 has a 11. For the showing hands, player I would score 4 hands, player 2 would score 5, and there would be l tie. Part of the pseudocode for this process could be: FOR Each Card in the Deck IF Player 1 has the higher card Increase player l's wins by 1 ELSE IF Player 2 has the higher card Increase player 2's wins by 1 ELSE IF There's a tie Increase number of ties by 1 ENDFOR 5. Print out how many wins each player has and how many ties were made. [E] Ask the user for the names of the two players and instead of displaying "Player 1" or "Player 2" throughout the program, use the player's names. [H] Allow ties to be broken by awarding the point for the tie to the player that wins the following hand. This means that the hand following a tie is worth 2 points instead of just one and a tie is worth nothingStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started