s 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 that both Players are human that manuelly pick which cards they pick instead of it automatically choosing itself and Player A starts. Player A picks a card in his/her hand. Player B gets to choose the two cards which add to the value of Player A’s card, if player B lies and the two cards they choose do not add up to A's card, player B loses a point, if player B does not have two cards whose value adds to the value of Player A’s card, then no one gets a point. Player’s A card (if selected) and the two cards from

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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 that both Players are human that manuelly pick which cards they pick instead of it automatically choosing itself and Player A starts. Player A picks a card in his/her hand. Player B gets to choose the two cards which add to the value of Player A’s card, if player B lies and the two cards they choose do not add up to A's card, player B loses a point, if player B does not have two cards whose value adds to the value of Player A’s card, then no one gets a point. Player’s A card (if selected) and the two cards from Player B are discarded both players draw back to 5 cards from the deck. 

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) {
// card game, two players, take turns.
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");
//changed the name of input string variable to remove the error
String PlayerName = sc.nextLine();
Player newPlayer = new Player(PlayerName);
listOfPlayers.add(newPlayer);
 
//adding another player to the list
System.out.println("Name of Player 2");
PlayerName = sc.nextLine();
Player newPlayer2 = new Player(PlayerName);
listOfPlayers.add(newPlayer2);
 
//now choosing Random cards for both players and then store it in the array.
List<String> Player1Cards = new ArrayList<>();
List<String> Player2Cards = new ArrayList<>();
 
for(int i=1;i<=5;i++){
//a card is "suitName" + "number"
int suitIndex1,suitIndex2;
int numbersIndex1,numbersIndex2;
Random random = new Random();
//suitIndex ranges from 0 to 3.
// numbersIndex ranges from 0 to 12.
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]);
}
//displaying cards choosen
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;
2
3
4
6
7
class Main {
public static void main(String[] args) {
// card game, two players, take turns.
string[] suits = {"Hearts", "Clubs", "Spades", "Diamonds"};
string[] numbers = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J",
"о", "к"};
8
9.
10
11
12
13
for(String oneSuit : suits){
for (String num : numbers){
14
15
16
17
System.out.println(oneSuit +
+ num);
18
19
}
}
//add a player to the list
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);
20
21
22
23
24
25
26
27
28
29
//adding another player to the list
system.out.println("Name of Player 2");
30
31
1.
Transcribed Image Text:Main.java import java.util.ArrayList; import java.util.Scanner; import java.util.List; import java.util.Random; 2 3 4 6 7 class Main { public static void main(String[] args) { // card game, two players, take turns. string[] suits = {"Hearts", "Clubs", "Spades", "Diamonds"}; string[] numbers = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "о", "к"}; 8 9. 10 11 12 13 for(String oneSuit : suits){ for (String num : numbers){ 14 15 16 17 System.out.println(oneSuit + + num); 18 19 } } //add a player to the list 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); 20 21 22 23 24 25 26 27 28 29 //adding another player to the list system.out.println("Name of Player 2"); 30 31 1.
Main.java
system.out.println("Name of Player 2");
PlayerName = sc.nextLine();
Player newPlayer2 = new Player (PlayerName);
listofplayers.add(newPlayer2);
//now choosing Random cards for both players and then store it in the array.
List<string> Player1Cards = new ArrayList<>();
List<string> Player2Cards = new ArrayList<>();|
for(int i=1;i<=5;i++){
int suitIndex1, suitIndex2;
31
32
33
34
35
36
37
38
39
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;
40
41
42
43
44
45
46
Player1Cards.add(suits[suitIndex1]+numbers[numbersIndex1]);
Player2Cards.add(suits[suitIndex2]+numbers[numbersIndex2]);
}
//displaying cards choosen
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+" ");
47
48
49
50
51
52
53
54
55
56
57
58
59
}
60
Transcribed Image Text:Main.java system.out.println("Name of Player 2"); PlayerName = sc.nextLine(); Player newPlayer2 = new Player (PlayerName); listofplayers.add(newPlayer2); //now choosing Random cards for both players and then store it in the array. List<string> Player1Cards = new ArrayList<>(); List<string> Player2Cards = new ArrayList<>();| for(int i=1;i<=5;i++){ int suitIndex1, suitIndex2; 31 32 33 34 35 36 37 38 39 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; 40 41 42 43 44 45 46 Player1Cards.add(suits[suitIndex1]+numbers[numbersIndex1]); Player2Cards.add(suits[suitIndex2]+numbers[numbersIndex2]); } //displaying cards choosen 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+" "); 47 48 49 50 51 52 53 54 55 56 57 58 59 } 60
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education