SlideShare uma empresa Scribd logo
1 de 4
Baixar para ler offline
can someone please update this code that is in java and help me get it to compile, showing the
fixed code?
import java.util.*;
import java.util.Scanner;
import java.util.Random;
public class BlackJack {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
/**
* This is the deck of cards, do not edit it unless you want to change the variable name
*/
ArrayList<String> deck = new ArrayList<String>(Arrays.asList(
"AH", "2H", "3H", "4H", "5H", "6H", "7H", "8H", "9H", "10H", "JH", "QH", "KH",
"AD", "2D", "3D", "4D", "5D", "6D", "7D", "8D", "9D", "10D", "JD", "QD", "KD",
"AC", "2C", "3C", "4C", "5C", "6C", "7C", "8C", "9C", "10C", "JC", "QC", "KC",
"AS", "2S", "3S", "4S", "5S", "6S", "7S", "8S", "9S", "10S", "JS", "QS", "KS"
));
System.out.println("Give me a seed.");
int seed = scnr.nextInt();
// Set the seed for the random number generator
Random random = new Random(seed);
System.out.println("How many humans would you like to play with?");
int numPlayers = scnr.nextInt();
// Create an array to hold the player scores
int[] playerScores = new int[numPlayers];
// Create an array to hold the player decks
ArrayList<String>[] playerDecks = new ArrayList[numPlayers];
for (int i = 0; i < numPlayers; i++) {
playerDecks[i] = new ArrayList<String>();
}
// Deal two cards to each player
for (int i = 0; i < numPlayers; i++) {
ArrayList<String> myDeck = playerDecks[i];
myDeck.add(dealCard(deck, random));
myDeck.add(dealCard(deck, random));
// Display the player's cards
System.out.println("Player " + (i + 1) + "'s cards:");
displayCards(myDeck);
// Wait for player to acknowledge their cards
System.out.println("Acknowledge that you have seen your cards player " + (i + 1) + " by entering
any key.");
scnr.next();
// Calculate and display the player's score
int score = calculateScore(myDeck);
playerScores[i] = score;
System.out.println("Player " + (i + 1) + "'s score: " + score);
}
// Play the game
boolean[] isBusted = new boolean[numPlayers];
boolean isAllStick = false;
while (!isAllStick) {
isAllStick = true;
for (int i = 0; i < numPlayers; i++) {
ArrayList<String> myDeck = playerDecks[i];
if (!isBusted[i]) {
// Ask player whether to hit or stick
System.out.println("Player " + (i + 1) + "'s cards: ");
displayCards(myDeck);
System.out.println("Player " + (i + 1) + " would you like to hit or stick?");
String response = scnr.next();
while (response.equalsIgnoreCase("hit")) {
myDeck.add(deck.remove(random.nextInt(deck.size())));
int score = calculateScore(myDeck);
if (score > 21) {
isBusted[i] = true;
System.out.println("Player " + (i + 1) + " has busted. Enter any key to acknowledge this.");
scnr.next();
break;
}
System.out.println("Player " + (i + 1) + "'s cards: ");
displayCards(myDeck);
System.out.println("Player " + (i + 1) + " would you like to hit or stick?");
response = scnr.next();
}
while (response.equalsIgnoreCase("hit")) {
myDeck.add(dealCard(random));
// If the player busts, mark them as busted and stop asking for more cards
if (score > 21) {
isBusted[i] = true;
System.out.println("Player " + (i + 1) + " has busted. Enter any key to acknowledge this.");
scnr.next();
break;
}
// Ask the player again whether to hit or stick
System.out.println("Player " + (i + 1) + " would you like to hit or stick?");
response = scnr.next();
}
while (response.equalsIgnoreCase("hit")) {
myDeck.add(deck.remove(random.nextInt(deck.size())));
int score = calculateScore(myDeck);
if (score > 21) {
System.out.println("Player " + (i + 1) + "'s cards: " + myDeck);
}
}
}
// Determine the maximum score that is not a bust
int maxScore = -1;
for (int i = 0; i < numPlayers; i++) {
int score = playerScores[i];
if (score <= 21 && score > maxScore) {
maxScore = score;
}
}
// Find the indices of the players with the maximum score
ArrayList<Integer> maxScoreIndices = new ArrayList<Integer>();
for (int i = 0; i < numPlayers; i++) {
if (playerScores[i] == maxScore) {
maxScoreIndices.add(i + 1);
}
}
// Print the winner or winners, or declare a tie
if (maxScoreIndices.size() == 1) {
System.out.println("Player " + maxScoreIndices.get(0) + " got the highest score of " + maxScore +
".");
} else if (maxScoreIndices.size() == numPlayers) {
System.out.println("Everybody busted.");
} else if (maxScoreIndices.size() == 2) {
System.out.print("Players ");
System.out.print(maxScoreIndices.get(0) + " ");
System.out.print("and " + maxScoreIndices.get(1));
System.out.println(" tied for the highest score of " + maxScore);
} else {
System.out.print("Players ");
for (int i = 0; i < maxScoreIndices.size() - 1; i++) {
System.out.print(maxScoreIndices.get(i) + ", ");
}
System.out.print("and " + maxScoreIndices.get(maxScoreIndices.size() - 1));
System.out.println(" tied for the highest score of " + maxScore);
}
System.out.println("Nobody won.");
}
}
}
}

Mais conteúdo relacionado

Semelhante a can someone please update this code that is in java and help.pdf

Here is the game description- Here is the sample game- Here is the req.pdf
Here is the game description- Here is the sample game- Here is the req.pdfHere is the game description- Here is the sample game- Here is the req.pdf
Here is the game description- Here is the sample game- Here is the req.pdftrishulinoverseas1
 
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdfObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdfrajkumarm401
 
groovy databases
groovy databasesgroovy databases
groovy databasesPaul King
 
Construct a java method.   This method chooses the number of sti.pdf
Construct a java method.    This method chooses the number of sti.pdfConstruct a java method.    This method chooses the number of sti.pdf
Construct a java method.   This method chooses the number of sti.pdfarihantmobilepoint15
 
Tic tac toe on c++ project
Tic tac toe on c++ projectTic tac toe on c++ project
Tic tac toe on c++ projectUtkarsh Aggarwal
 
Please help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdfPlease help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdfmanjan6
 
import java.awt.;import java.awt.event.;import javax.swing.;.pdf
import java.awt.;import java.awt.event.;import javax.swing.;.pdfimport java.awt.;import java.awt.event.;import javax.swing.;.pdf
import java.awt.;import java.awt.event.;import javax.swing.;.pdfaoneonlinestore1
 

Semelhante a can someone please update this code that is in java and help.pdf (7)

Here is the game description- Here is the sample game- Here is the req.pdf
Here is the game description- Here is the sample game- Here is the req.pdfHere is the game description- Here is the sample game- Here is the req.pdf
Here is the game description- Here is the sample game- Here is the req.pdf
 
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdfObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
 
groovy databases
groovy databasesgroovy databases
groovy databases
 
Construct a java method.   This method chooses the number of sti.pdf
Construct a java method.    This method chooses the number of sti.pdfConstruct a java method.    This method chooses the number of sti.pdf
Construct a java method.   This method chooses the number of sti.pdf
 
Tic tac toe on c++ project
Tic tac toe on c++ projectTic tac toe on c++ project
Tic tac toe on c++ project
 
Please help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdfPlease help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdf
 
import java.awt.;import java.awt.event.;import javax.swing.;.pdf
import java.awt.;import java.awt.event.;import javax.swing.;.pdfimport java.awt.;import java.awt.event.;import javax.swing.;.pdf
import java.awt.;import java.awt.event.;import javax.swing.;.pdf
 

Mais de akshpatil4

Calculate the amount of money Paige had to deposit in an inv.pdf
Calculate the amount of money Paige had to deposit in an inv.pdfCalculate the amount of money Paige had to deposit in an inv.pdf
Calculate the amount of money Paige had to deposit in an inv.pdfakshpatil4
 
Cada ao en los Estados Unidos cientos de iglesias cristian.pdf
Cada ao en los Estados Unidos cientos de iglesias cristian.pdfCada ao en los Estados Unidos cientos de iglesias cristian.pdf
Cada ao en los Estados Unidos cientos de iglesias cristian.pdfakshpatil4
 
Can you please add comments so I can understand it Thank yo.pdf
Can you please add comments so I can understand it Thank yo.pdfCan you please add comments so I can understand it Thank yo.pdf
Can you please add comments so I can understand it Thank yo.pdfakshpatil4
 
can you help me write this code in Net Maui App please than.pdf
can you help me write this code in Net Maui App please than.pdfcan you help me write this code in Net Maui App please than.pdf
can you help me write this code in Net Maui App please than.pdfakshpatil4
 
Can you help me with these two questions I will give you a .pdf
Can you help me with these two questions I will give you a .pdfCan you help me with these two questions I will give you a .pdf
Can you help me with these two questions I will give you a .pdfakshpatil4
 
Can you help me design this interface in HTML Flight Find.pdf
Can you help me design this interface in HTML   Flight Find.pdfCan you help me design this interface in HTML   Flight Find.pdf
Can you help me design this interface in HTML Flight Find.pdfakshpatil4
 
Can You build the web based project Homepage for me Home .pdf
Can You build the web based project Homepage for me   Home .pdfCan You build the web based project Homepage for me   Home .pdf
Can You build the web based project Homepage for me Home .pdfakshpatil4
 
Can You build the web based project for me Home Page Aft.pdf
Can You build the web based project for me   Home Page Aft.pdfCan You build the web based project for me   Home Page Aft.pdf
Can You build the web based project for me Home Page Aft.pdfakshpatil4
 
can you break this down in python codes please Task 1 Cre.pdf
can you break this down in python codes please  Task 1 Cre.pdfcan you break this down in python codes please  Task 1 Cre.pdf
can you break this down in python codes please Task 1 Cre.pdfakshpatil4
 
Can someone explain this to me step by step Consider a give.pdf
Can someone explain this to me step by step Consider a give.pdfCan someone explain this to me step by step Consider a give.pdf
Can someone explain this to me step by step Consider a give.pdfakshpatil4
 
Can you answer these True or False questions for me please .pdf
Can you answer these True or False questions for me please .pdfCan you answer these True or False questions for me please .pdf
Can you answer these True or False questions for me please .pdfakshpatil4
 
Can someone please help with this Now that you have compl.pdf
Can someone please help with this  Now that you have compl.pdfCan someone please help with this  Now that you have compl.pdf
Can someone please help with this Now that you have compl.pdfakshpatil4
 
Can someone solve the TODO parts of the following problem i.pdf
Can someone solve the TODO parts of the following problem i.pdfCan someone solve the TODO parts of the following problem i.pdf
Can someone solve the TODO parts of the following problem i.pdfakshpatil4
 
Calculate the amount of money Dylan had to deposit in an inv.pdf
Calculate the amount of money Dylan had to deposit in an inv.pdfCalculate the amount of money Dylan had to deposit in an inv.pdf
Calculate the amount of money Dylan had to deposit in an inv.pdfakshpatil4
 
Can someone please help me implement the addSong function .pdf
Can someone please help me implement the addSong function .pdfCan someone please help me implement the addSong function .pdf
Can someone please help me implement the addSong function .pdfakshpatil4
 
Can someone please help me complete the add_song function .pdf
Can someone please help me complete the add_song function .pdfCan someone please help me complete the add_song function .pdf
Can someone please help me complete the add_song function .pdfakshpatil4
 
can someone please assist me with analysis of this case atud.pdf
can someone please assist me with analysis of this case atud.pdfcan someone please assist me with analysis of this case atud.pdf
can someone please assist me with analysis of this case atud.pdfakshpatil4
 
can someone help me with this class ENVS 200040 Pollution.pdf
can someone help me with this class ENVS 200040   Pollution.pdfcan someone help me with this class ENVS 200040   Pollution.pdf
can someone help me with this class ENVS 200040 Pollution.pdfakshpatil4
 
Can someone help me with these questions 1 Main structures.pdf
Can someone help me with these questions 1 Main structures.pdfCan someone help me with these questions 1 Main structures.pdf
Can someone help me with these questions 1 Main structures.pdfakshpatil4
 
Can someone help with these functions doAddTweet doEditTwe.pdf
Can someone help with these functions  doAddTweet doEditTwe.pdfCan someone help with these functions  doAddTweet doEditTwe.pdf
Can someone help with these functions doAddTweet doEditTwe.pdfakshpatil4
 

Mais de akshpatil4 (20)

Calculate the amount of money Paige had to deposit in an inv.pdf
Calculate the amount of money Paige had to deposit in an inv.pdfCalculate the amount of money Paige had to deposit in an inv.pdf
Calculate the amount of money Paige had to deposit in an inv.pdf
 
Cada ao en los Estados Unidos cientos de iglesias cristian.pdf
Cada ao en los Estados Unidos cientos de iglesias cristian.pdfCada ao en los Estados Unidos cientos de iglesias cristian.pdf
Cada ao en los Estados Unidos cientos de iglesias cristian.pdf
 
Can you please add comments so I can understand it Thank yo.pdf
Can you please add comments so I can understand it Thank yo.pdfCan you please add comments so I can understand it Thank yo.pdf
Can you please add comments so I can understand it Thank yo.pdf
 
can you help me write this code in Net Maui App please than.pdf
can you help me write this code in Net Maui App please than.pdfcan you help me write this code in Net Maui App please than.pdf
can you help me write this code in Net Maui App please than.pdf
 
Can you help me with these two questions I will give you a .pdf
Can you help me with these two questions I will give you a .pdfCan you help me with these two questions I will give you a .pdf
Can you help me with these two questions I will give you a .pdf
 
Can you help me design this interface in HTML Flight Find.pdf
Can you help me design this interface in HTML   Flight Find.pdfCan you help me design this interface in HTML   Flight Find.pdf
Can you help me design this interface in HTML Flight Find.pdf
 
Can You build the web based project Homepage for me Home .pdf
Can You build the web based project Homepage for me   Home .pdfCan You build the web based project Homepage for me   Home .pdf
Can You build the web based project Homepage for me Home .pdf
 
Can You build the web based project for me Home Page Aft.pdf
Can You build the web based project for me   Home Page Aft.pdfCan You build the web based project for me   Home Page Aft.pdf
Can You build the web based project for me Home Page Aft.pdf
 
can you break this down in python codes please Task 1 Cre.pdf
can you break this down in python codes please  Task 1 Cre.pdfcan you break this down in python codes please  Task 1 Cre.pdf
can you break this down in python codes please Task 1 Cre.pdf
 
Can someone explain this to me step by step Consider a give.pdf
Can someone explain this to me step by step Consider a give.pdfCan someone explain this to me step by step Consider a give.pdf
Can someone explain this to me step by step Consider a give.pdf
 
Can you answer these True or False questions for me please .pdf
Can you answer these True or False questions for me please .pdfCan you answer these True or False questions for me please .pdf
Can you answer these True or False questions for me please .pdf
 
Can someone please help with this Now that you have compl.pdf
Can someone please help with this  Now that you have compl.pdfCan someone please help with this  Now that you have compl.pdf
Can someone please help with this Now that you have compl.pdf
 
Can someone solve the TODO parts of the following problem i.pdf
Can someone solve the TODO parts of the following problem i.pdfCan someone solve the TODO parts of the following problem i.pdf
Can someone solve the TODO parts of the following problem i.pdf
 
Calculate the amount of money Dylan had to deposit in an inv.pdf
Calculate the amount of money Dylan had to deposit in an inv.pdfCalculate the amount of money Dylan had to deposit in an inv.pdf
Calculate the amount of money Dylan had to deposit in an inv.pdf
 
Can someone please help me implement the addSong function .pdf
Can someone please help me implement the addSong function .pdfCan someone please help me implement the addSong function .pdf
Can someone please help me implement the addSong function .pdf
 
Can someone please help me complete the add_song function .pdf
Can someone please help me complete the add_song function .pdfCan someone please help me complete the add_song function .pdf
Can someone please help me complete the add_song function .pdf
 
can someone please assist me with analysis of this case atud.pdf
can someone please assist me with analysis of this case atud.pdfcan someone please assist me with analysis of this case atud.pdf
can someone please assist me with analysis of this case atud.pdf
 
can someone help me with this class ENVS 200040 Pollution.pdf
can someone help me with this class ENVS 200040   Pollution.pdfcan someone help me with this class ENVS 200040   Pollution.pdf
can someone help me with this class ENVS 200040 Pollution.pdf
 
Can someone help me with these questions 1 Main structures.pdf
Can someone help me with these questions 1 Main structures.pdfCan someone help me with these questions 1 Main structures.pdf
Can someone help me with these questions 1 Main structures.pdf
 
Can someone help with these functions doAddTweet doEditTwe.pdf
Can someone help with these functions  doAddTweet doEditTwe.pdfCan someone help with these functions  doAddTweet doEditTwe.pdf
Can someone help with these functions doAddTweet doEditTwe.pdf
 

Último

Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 

Último (20)

Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 

can someone please update this code that is in java and help.pdf

  • 1. can someone please update this code that is in java and help me get it to compile, showing the fixed code? import java.util.*; import java.util.Scanner; import java.util.Random; public class BlackJack { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); /** * This is the deck of cards, do not edit it unless you want to change the variable name */ ArrayList<String> deck = new ArrayList<String>(Arrays.asList( "AH", "2H", "3H", "4H", "5H", "6H", "7H", "8H", "9H", "10H", "JH", "QH", "KH", "AD", "2D", "3D", "4D", "5D", "6D", "7D", "8D", "9D", "10D", "JD", "QD", "KD", "AC", "2C", "3C", "4C", "5C", "6C", "7C", "8C", "9C", "10C", "JC", "QC", "KC", "AS", "2S", "3S", "4S", "5S", "6S", "7S", "8S", "9S", "10S", "JS", "QS", "KS" )); System.out.println("Give me a seed."); int seed = scnr.nextInt(); // Set the seed for the random number generator Random random = new Random(seed); System.out.println("How many humans would you like to play with?"); int numPlayers = scnr.nextInt(); // Create an array to hold the player scores int[] playerScores = new int[numPlayers]; // Create an array to hold the player decks ArrayList<String>[] playerDecks = new ArrayList[numPlayers]; for (int i = 0; i < numPlayers; i++) { playerDecks[i] = new ArrayList<String>(); } // Deal two cards to each player for (int i = 0; i < numPlayers; i++) { ArrayList<String> myDeck = playerDecks[i]; myDeck.add(dealCard(deck, random)); myDeck.add(dealCard(deck, random)); // Display the player's cards System.out.println("Player " + (i + 1) + "'s cards:"); displayCards(myDeck); // Wait for player to acknowledge their cards System.out.println("Acknowledge that you have seen your cards player " + (i + 1) + " by entering any key."); scnr.next();
  • 2. // Calculate and display the player's score int score = calculateScore(myDeck); playerScores[i] = score; System.out.println("Player " + (i + 1) + "'s score: " + score); } // Play the game boolean[] isBusted = new boolean[numPlayers]; boolean isAllStick = false; while (!isAllStick) { isAllStick = true; for (int i = 0; i < numPlayers; i++) { ArrayList<String> myDeck = playerDecks[i]; if (!isBusted[i]) { // Ask player whether to hit or stick System.out.println("Player " + (i + 1) + "'s cards: "); displayCards(myDeck); System.out.println("Player " + (i + 1) + " would you like to hit or stick?"); String response = scnr.next(); while (response.equalsIgnoreCase("hit")) { myDeck.add(deck.remove(random.nextInt(deck.size()))); int score = calculateScore(myDeck); if (score > 21) { isBusted[i] = true; System.out.println("Player " + (i + 1) + " has busted. Enter any key to acknowledge this."); scnr.next(); break; } System.out.println("Player " + (i + 1) + "'s cards: "); displayCards(myDeck); System.out.println("Player " + (i + 1) + " would you like to hit or stick?"); response = scnr.next(); } while (response.equalsIgnoreCase("hit")) { myDeck.add(dealCard(random)); // If the player busts, mark them as busted and stop asking for more cards if (score > 21) { isBusted[i] = true; System.out.println("Player " + (i + 1) + " has busted. Enter any key to acknowledge this."); scnr.next(); break; } // Ask the player again whether to hit or stick
  • 3. System.out.println("Player " + (i + 1) + " would you like to hit or stick?"); response = scnr.next(); } while (response.equalsIgnoreCase("hit")) { myDeck.add(deck.remove(random.nextInt(deck.size()))); int score = calculateScore(myDeck); if (score > 21) { System.out.println("Player " + (i + 1) + "'s cards: " + myDeck); } } } // Determine the maximum score that is not a bust int maxScore = -1; for (int i = 0; i < numPlayers; i++) { int score = playerScores[i]; if (score <= 21 && score > maxScore) { maxScore = score; } } // Find the indices of the players with the maximum score ArrayList<Integer> maxScoreIndices = new ArrayList<Integer>(); for (int i = 0; i < numPlayers; i++) { if (playerScores[i] == maxScore) { maxScoreIndices.add(i + 1); } } // Print the winner or winners, or declare a tie if (maxScoreIndices.size() == 1) { System.out.println("Player " + maxScoreIndices.get(0) + " got the highest score of " + maxScore + "."); } else if (maxScoreIndices.size() == numPlayers) { System.out.println("Everybody busted."); } else if (maxScoreIndices.size() == 2) { System.out.print("Players "); System.out.print(maxScoreIndices.get(0) + " "); System.out.print("and " + maxScoreIndices.get(1)); System.out.println(" tied for the highest score of " + maxScore); } else { System.out.print("Players "); for (int i = 0; i < maxScoreIndices.size() - 1; i++) { System.out.print(maxScoreIndices.get(i) + ", "); }
  • 4. System.out.print("and " + maxScoreIndices.get(maxScoreIndices.size() - 1)); System.out.println(" tied for the highest score of " + maxScore); } System.out.println("Nobody won."); } } } }