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. What I want to be added into the code is a way for player1 to select a one card from his deck and player2 has to select two cards from his deck that equals player1's card. If player2 can't pick two cards that equal player1's one card than player2 losses a point but if player2 can select two cards that equal player1's card tahn player2 gets a point.  Main class:  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 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 Player1Cards = new ArrayList<>(); List 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 + " "); } } }

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...
icon
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. What I want to be added into the code is a way for player1 to select a one card from his deck and player2 has to select two cards from his deck that equals player1's card. If player2 can't pick two cards that equal player1's one card than player2 losses a point but if player2 can select two cards that equal player1's card tahn player2 gets a point. 

Main class: 

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 + " ");
}
}
}
Main.java
import java.util.ArrayList;
import java.util.Scanner;
import java.util.List;
import java.util.Random;
1
2
3
4
5
6
class Main {
public static void main(String[] args) {
String[] suits = { "Hearts", "clubs", "Spades", "Diamonds" };
String[] numbers
"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<>();
7
8
{ "A", "2", "3", "4", "5", "6", "7", "8", "9",
9.
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
for (int i = 1; i <= 5; i++) {
int suitIndex1, suitIndex2;
int numbersIndex1, numbersIndex2;
= new Random();
29
30
31
Random random
Transcribed Image Text:Main.java import java.util.ArrayList; import java.util.Scanner; import java.util.List; import java.util.Random; 1 2 3 4 5 6 class Main { public static void main(String[] args) { String[] suits = { "Hearts", "clubs", "Spades", "Diamonds" }; String[] numbers "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<>(); 7 8 { "A", "2", "3", "4", "5", "6", "7", "8", "9", 9. 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 for (int i = 1; i <= 5; i++) { int suitIndex1, suitIndex2; int numbersIndex1, numbersIndex2; = new Random(); 29 30 31 Random random
Main.java
suitIndex1 = random.nextInt(3 - 0) + 0;
numbersIndex1 = random.nextInt (12 - 0) + 0;
suitIndex2 = random.nextInt(3 - 0) + 0;
numbersIndex2 = random.nextInt(12 - 0) + 0;
32
33
34
35
36
Player1Cards.add (suits[suitIndex1] + numbers[numbersIndex1]);
Player2Cards.add (suits[suitIndex2] + numbers[numbersIndex2]);
}
System.out.print("Player " + newPlayer.getName() +
37
38
39
40
cards are: ")
for (String card : Player1Cards) {
System.out.print(card + " ");
}
System.out.print("\nPlayer " + newPlayer2.getName() +
are: ");
for (String card : Player2Cards) {
System.out.print(card + " ");
}
}
}
41
42
43
44
" cards
45
46
47
48
49
Transcribed Image Text:Main.java suitIndex1 = random.nextInt(3 - 0) + 0; numbersIndex1 = random.nextInt (12 - 0) + 0; suitIndex2 = random.nextInt(3 - 0) + 0; numbersIndex2 = random.nextInt(12 - 0) + 0; 32 33 34 35 36 Player1Cards.add (suits[suitIndex1] + numbers[numbersIndex1]); Player2Cards.add (suits[suitIndex2] + numbers[numbersIndex2]); } System.out.print("Player " + newPlayer.getName() + 37 38 39 40 cards are: ") for (String card : Player1Cards) { System.out.print(card + " "); } System.out.print("\nPlayer " + newPlayer2.getName() + are: "); for (String card : Player2Cards) { System.out.print(card + " "); } } } 41 42 43 44 " cards 45 46 47 48 49
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
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 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)
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
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY