For the code in java below it shows a deck of 52 cards and asks the name of the two players and makes both players draw five cards from the deck. The code also makes Player A pick a card and Player B has to pick two cards that equal the same value as Player A's card. What I want to be added to the code if for the cards that have been used to be removed and replaced with the other cards in the deck and for the next round to begin with Player B picking a card and Player A picking two cards that equal the same value as Player B's card. I also want the game to keep going between Player A and B until the cards in the deck run out.
For the code in java below it shows a deck of 52 cards and asks the name of the two players and makes both players draw five cards from the deck. The code also makes Player A pick a card and Player B has to pick two cards that equal the same value as Player A's card. What I want to be added to the code if for the cards that have been used to be removed and replaced with the other cards in the deck and for the next round to begin with Player B picking a card and Player A picking two cards that equal the same value as Player B's card. I also want the game to keep going between Player A and B until the cards in the deck run out.
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
For the code in java below it shows a deck of 52 cards and asks the name of the two players and makes both players draw five cards from the deck. The code also makes Player A pick a card and Player B has to pick two cards that equal the same value as Player A's card.
What I want to be added to the code if for the cards that have been used to be removed and replaced with the other cards in the deck and for the next round to begin with Player B picking a card and Player A picking two cards that equal the same value as Player B's card.
I also want the game to keep going between Player A and B until the cards in the deck run out.
Main class code:
import java.util.ArrayList;
import java.util.Scanner;
import java.util.List;
import java.util.Random;
class Main {
publicstaticvoid main(String[] args) {
String[] suits = {"Hearts", "Clubs", "Spades", "Diamonds"};
String[] numbers = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};
for(String oneSuit : suits){
for(String num : numbers){
System.out.println(oneSuit + " " + num);
}
}
List<Player> listOfPlayers = new ArrayList<>();
Scanner sc = new Scanner(System.in);
System.out.println("Name of Player 1");
String PlayerName = sc.nextLine();
Player newPlayer = new Player(PlayerName);
listOfPlayers.add(newPlayer);
System.out.println("Name of Player 2");
PlayerName = sc.nextLine();
Player newPlayer2 = new Player(PlayerName);
listOfPlayers.add(newPlayer2);
List<String> Player1Cards = new ArrayList<>();
List<String> Player2Cards = new ArrayList<>();
for(int i=1;i<=5;i++){
int suitIndex1,suitIndex2;
int numbersIndex1,numbersIndex2;
Random random = new Random();
suitIndex1 = random.nextInt(3 - 0) + 0;
numbersIndex1= random.nextInt(12 - 0) + 0;
suitIndex2 = random.nextInt(3 - 0) + 0;
numbersIndex2= random.nextInt(12 - 0) + 0;
Player1Cards.add(suits[suitIndex1]+numbers[numbersIndex1]);
Player2Cards.add(suits[suitIndex2]+numbers[numbersIndex2]);
}
System.out.print("Player "+newPlayer.getName()+" cards are: ");
for(String card:Player1Cards){
System.out.print(card+" ");
}
System.out.print("\nPlayer "+newPlayer2.getName()+" cards are: ");
for(String card:Player2Cards){
System.out.print(card+" ");
}
System.out.println("\nCard selected by Player 1: ");
int selectedIndex1;
Random random = new Random();
selectedIndex1 = random.nextInt(4 - 0) + 0;
String selectedcardP1 = Player1Cards.get(selectedIndex1);
System.out.println(selectedcardP1);
System.out.println("First Card selected by Player 2: ");
int selectedIndex2, selectedIndex3;
selectedIndex2 = random.nextInt(4 - 0) + 0;
String selectedcardP2 = Player2Cards.get(selectedIndex2);
System.out.println(selectedcardP2);
if(selectedcardP1.equals(selectedcardP2)) {
System.out.println("Player 2 gets a point");
}
else {
selectedIndex3 = random.nextInt(4 - 0) + 0;
while(selectedIndex3 == selectedIndex2) {
selectedIndex3 = random.nextInt(4 - 0) + 0;
}
System.out.println("Second Card selected by Player 2: ");
selectedcardP2 = Player2Cards.get(selectedIndex3);
System.out.println(selectedcardP2);
if(selectedcardP1.equals(selectedcardP2)){
System.out.println("Player 2 gets a point");
}
else {
System.out.println("Nobody gets a point");
}
}
}
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY