Discover a world of knowledge at Westonci.ca, where experts and enthusiasts come together to answer your questions. Discover precise answers to your questions from a wide range of experts on our user-friendly Q&A platform. Get immediate and reliable solutions to your questions from a community of experienced professionals on our platform.
Sagot :
Answer:
Explanation:
The following code is written in Java. It is a function that creates a Random object to generate random values, then uses those values to choose a random rank and suit using switch statements. It then saves the rank and suit into a String variable in the correct format and finally prints the card that was picked to the screen. The function was called 4 times in the main method and the output can be seen in the attached image below.
public static void randomCardGenerator() {
Random rand = new Random();
int rank = rand.nextInt(14)+1;
int suit = rand.nextInt(4)+1;
String chosenCard = "";
switch (rank) {
case 1: chosenCard += "Ace"; break;
case 2: chosenCard += "1"; break;
case 3: chosenCard += "2"; break;
case 4: chosenCard += "3"; break;
case 5: chosenCard += "4"; break;
case 6: chosenCard += "5"; break;
case 7: chosenCard += "6"; break;
case 8: chosenCard += "7"; break;
case 9: chosenCard += "8"; break;
case 10: chosenCard += "9"; break;
case 11: chosenCard += "10"; break;
case 12: chosenCard += "Jack"; break;
case 13: chosenCard += "Queen"; break;
case 14: chosenCard += "Kind"; break;
default: System.out.println("Wrong Value");
}
chosenCard += " of ";
switch (suit) {
case 1: chosenCard += "Clubs"; break;
case 2: chosenCard += "Diamonds"; break;
case 3: chosenCard += "Hearts"; break;
case 4: chosenCard += "Spades"; break;
default: System.out.println("Invalid Suit");
}
System.out.println(chosenCard);
}
Visit us again for up-to-date and reliable answers. We're always ready to assist you with your informational needs. Thank you for your visit. We're committed to providing you with the best information available. Return anytime for more. We're glad you chose Westonci.ca. Revisit us for updated answers from our knowledgeable team.