SlideShare ist ein Scribd-Unternehmen logo
1 von 4
Downloaden Sie, um offline zu lesen
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.");
}
}
}
}

Weitere ähnliche Inhalte

Ähnlich wie 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.pdf
trishulinoverseas1
 
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
rajkumarm401
 
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
arihantmobilepoint15
 
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
manjan6
 
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
aoneonlinestore1
 

Ähnlich wie 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
 

Mehr von akshpatil4

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
akshpatil4
 
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
akshpatil4
 
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
akshpatil4
 
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
akshpatil4
 
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
akshpatil4
 
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
akshpatil4
 
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
akshpatil4
 
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
akshpatil4
 
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
akshpatil4
 

Mehr von 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
 

Kürzlich hochgeladen

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 

Kürzlich hochgeladen (20)

Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
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Ữ Â...
 
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
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 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.
 
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
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
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
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 

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."); } } } }