blackjack

Category: Programming
Author: Benson Limketkai
Book Chapter: 5.4
Problem: blackjack
Write a static method blackjack that prints random numbers in the range of 1 – 10 until the sum of all integers generated are greater than or equal to 17. The sum is subsequently printed. If the sum is greater than 21, then the method prints out "Busted!"; if the sum is equal to 21, then the method prints out "BLACKJACK!". The method returns whether the sum was less than or equal to 21.

Here are some example calls on blackjack():

     +---------------------------+---------+
     | Prints                    | Returns |
     +---------------------------+---------+
     | 2 4 6 10 = 22 Busted!     | false   |
     +---------------------------+---------+
     | 2 2 1 5 7 = 17            | true    |
     +---------------------------+---------+
     | 9 5 7 = 21 BLACKJACK!     | true    |
     +---------------------------+---------+
     | 5 6 3 2 10 = 26 Busted!   | false   |
     +---------------------------+---------+
     | 10 5 4 = 19               | true    |
     +---------------------------+---------+

As this method has an element of randomness to it, you are to copy the format of the output, not the exact output of the sample calls.