Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3. In the game of blackjack the player can draw cards from a deck until the sum

ID: 3861577 • Letter: 3

Question

3. In the game of blackjack the player can draw cards from a deck until the sum of their card values reaches 21. Create a while loop. In each iteration generate a random number between 2 and 11. Add all these random numbers together until their sum becomes greater than or equal to 21. Then print out the sum and the number of cards dealt. Use this line of code to generate the number: new_card = floor(rand(1,1) * 10 + 2); Sample Output: >> blackjack Hand Score = 21, Number of Cards = 3 >> blackjack Hand Score = 26, Number of Cards = 4 >> blackjack Hand Score = 24, Number of Cards = 4 ASAP please and thanks! 3. In the game of blackjack the player can draw cards from a deck until the sum of their card values reaches 21. Create a while loop. In each iteration generate a random number between 2 and 11. Add all these random numbers together until their sum becomes greater than or equal to 21. Then print out the sum and the number of cards dealt. Use this line of code to generate the number: new_card = floor(rand(1,1) * 10 + 2); Sample Output: >> blackjack Hand Score = 21, Number of Cards = 3 >> blackjack Hand Score = 26, Number of Cards = 4 >> blackjack Hand Score = 24, Number of Cards = 4 ASAP please and thanks! 3. In the game of blackjack the player can draw cards from a deck until the sum of their card values reaches 21. Create a while loop. In each iteration generate a random number between 2 and 11. Add all these random numbers together until their sum becomes greater than or equal to 21. Then print out the sum and the number of cards dealt. Use this line of code to generate the number: new_card = floor(rand(1,1) * 10 + 2); Sample Output: >> blackjack Hand Score = 21, Number of Cards = 3 >> blackjack Hand Score = 26, Number of Cards = 4 >> blackjack Hand Score = 24, Number of Cards = 4 ASAP please and thanks!

Explanation / Answer

ANSWER:

import java.util.Random;

public class Game {

   public static void main(String[] args) {
       Random random = new Random();
       int low = 2;
       int high = 11;
       int totalSum = 21;
       int sum = 0;
       int cards = 0;

       while (true) {
           int new_card = (int) Math.floor(random.nextInt(high - low + 1) + low);
           sum = sum + new_card;
           cards++;
           if(sum >= totalSum)
               break;
       }
       System.out.println("Hand Score = "+sum+", Number of Cards = "+cards+" >> blackjack");
   }

}

Explanation:

1) Here I am develop code in JAVA, please find above

2) While loop continues untill, the sum is >= totalSum(21)

3) Its working fine.

Let me know any concerns. Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote