Statistics

Problem Statement for "BlackjackWinner"

Problem Statement

In the game of blackjack, if the player scores higher than the dealer or the dealer goes over 21, and the player does not go over 21, then he wins his bet (in addition to keeping his original wager). If he scores 21 or less, and the same as the dealer, the hand is a push, and he keeps his bet. Otherwise, if he scores lower than the dealer, or goes over 21 (regardless of whether or not the dealer also does so), then he loses his bet.

A "blackjack" is a special kind of 21 point hand that beats all other hands. In such a case, the player wins 1.5 times his original bet. If both dealer and player have a blackjack, then the hand is a push. Note that if the dealer has a blackjack, and the player has a 21 (but does not have blackjack), then the dealer wins, and the player loses his wager.

You are given an int bet indicating the players wager, an int dealer indicating the dealer's score, and an int player indicating the player's score. Finally, you are given an int blackjack, which will be equal to 1 if the player has a blackjack, or 0 otherwise. Likewise, you are given the int dealerBlackjack.

You are to return the amount of money the player wins or loses on the hand. A win should return a positive number, either the player's bet, or 1.5 times his bet. A loss should be returned as a negative number. A push should return 0.

Definition

Class:
BlackjackWinner
Method:
winnings
Parameters:
int, int, int, int, int
Returns:
int
Method signature:
int winnings(int bet, int dealer, int dealerBlackjack, int player, int blackjack)
(be sure your method is public)

Constraints

  • bet will be between 2 and 100, inclusive, and will be even.
  • dealer will be between 17 and 26, inclusive.
  • dealerBlackjack will be 0 or 1.
  • dealerBlackjack may only be 1 if dealer is 21.
  • player will be between 4 and 30, inclusive.
  • blackjack will be 0 or 1.
  • blackjack may only be 1 if player is 21.

Examples

  1. 10

    20

    0

    21

    0

    Returns: 10

    Here, the player beats the dealer (without blackjack), and wins his bet.

  2. 26

    21

    1

    21

    0

    Returns: -26

    Here, the player loses... even though both dealer and player have 21, the dealer has a blackjack.

  3. 100

    25

    0

    21

    1

    Returns: 150

    Here, the dealer went over, so as long as the player didn't go over, he's a winner. In fact, since he has a blackjack, he wins 1.5 times his original bet.

  4. 78

    22

    0

    23

    0

    Returns: -78

    Even though the dealer went over, so did the player, so the player loses.

  5. 80

    24

    0

    24

    0

    Returns: -80

  6. 2

    19

    0

    6

    0

    Returns: -2

  7. 4

    21

    1

    16

    0

    Returns: -4

  8. 68

    17

    0

    27

    0

    Returns: -68

  9. 28

    21

    0

    8

    0

    Returns: -28

  10. 34

    17

    0

    20

    0

    Returns: 34

  11. 36

    17

    0

    8

    0

    Returns: -36

  12. 2

    17

    0

    23

    0

    Returns: -2

  13. 98

    19

    0

    25

    0

    Returns: -98

  14. 54

    21

    0

    26

    0

    Returns: -54

  15. 4

    18

    0

    22

    0

    Returns: -4

  16. 78

    17

    0

    28

    0

    Returns: -78

  17. 94

    24

    0

    29

    0

    Returns: -94

  18. 6

    22

    0

    17

    0

    Returns: 6

  19. 48

    24

    0

    24

    0

    Returns: -48

  20. 6

    26

    0

    23

    0

    Returns: -6

  21. 4

    18

    0

    18

    0

    Returns: 0

  22. 78

    21

    1

    22

    0

    Returns: -78

  23. 98

    19

    0

    14

    0

    Returns: -98

  24. 10

    22

    0

    15

    0

    Returns: 10

  25. 60

    21

    0

    21

    1

    Returns: 90

  26. 10

    21

    0

    21

    1

    Returns: 15

  27. 20

    21

    1

    21

    1

    Returns: 0

  28. 100

    25

    0

    25

    0

    Returns: -100

  29. 10

    20

    0

    21

    1

    Returns: 15

  30. 32

    19

    0

    13

    0

    Returns: -32

  31. 10

    25

    0

    20

    0

    Returns: 10

  32. 10

    22

    0

    20

    0

    Returns: 10

  33. 100

    25

    0

    21

    0

    Returns: 100

  34. 10

    23

    0

    21

    0

    Returns: 10

  35. 10

    21

    1

    21

    0

    Returns: -10

  36. 10

    21

    1

    10

    0

    Returns: -10

  37. 50

    24

    0

    18

    0

    Returns: 50

  38. 10

    22

    0

    22

    0

    Returns: -10

  39. 16

    19

    0

    20

    0

    Returns: 16

  40. 60

    21

    1

    21

    1

    Returns: 0

  41. 100

    25

    0

    21

    1

    Returns: 150

  42. 10

    17

    0

    17

    0

    Returns: 0

  43. 10

    21

    1

    20

    0

    Returns: -10

  44. 50

    20

    0

    19

    0

    Returns: -50

  45. 2

    17

    0

    21

    1

    Returns: 3

  46. 10

    20

    0

    20

    0

    Returns: 0

  47. 100

    17

    0

    21

    1

    Returns: 150

  48. 2

    17

    0

    21

    0

    Returns: 2

  49. 10

    18

    0

    21

    1

    Returns: 15

  50. 100

    21

    0

    21

    1

    Returns: 150

  51. 10

    21

    0

    21

    0

    Returns: 0

  52. 50

    26

    0

    20

    0

    Returns: 50

  53. 100

    21

    1

    21

    1

    Returns: 0

  54. 10

    21

    1

    21

    1

    Returns: 0

  55. 20

    23

    0

    22

    0

    Returns: -20

  56. 10

    23

    0

    20

    0

    Returns: 10

  57. 2

    26

    0

    21

    0

    Returns: 2

  58. 10

    24

    0

    19

    0

    Returns: 10

  59. 50

    21

    0

    21

    1

    Returns: 75

  60. 2

    23

    0

    22

    0

    Returns: -2

  61. 10

    25

    0

    25

    0

    Returns: -10

  62. 10

    17

    0

    21

    1

    Returns: 15

  63. 26

    21

    1

    21

    1

    Returns: 0

  64. 10

    23

    0

    18

    0

    Returns: 10

  65. 2

    21

    1

    21

    1

    Returns: 0

  66. 20

    20

    0

    19

    0

    Returns: -20

  67. 100

    17

    0

    17

    0

    Returns: 0

  68. 100

    22

    0

    21

    0

    Returns: 100

  69. 100

    22

    0

    20

    0

    Returns: 100

  70. 10

    21

    0

    22

    0

    Returns: -10

  71. 100

    23

    0

    20

    0

    Returns: 100

  72. 100

    21

    0

    21

    0

    Returns: 0

  73. 20

    20

    0

    21

    1

    Returns: 30

  74. 2

    22

    0

    21

    0

    Returns: 2

  75. 10

    21

    1

    22

    0

    Returns: -10

  76. 100

    19

    0

    22

    0

    Returns: -100


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: