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
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
10
20
0
21
0
Returns: 10
Here, the player beats the dealer (without blackjack), and wins his bet.
26
21
1
21
0
Returns: -26
Here, the player loses... even though both dealer and player have 21, the dealer has a blackjack.
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.
78
22
0
23
0
Returns: -78
Even though the dealer went over, so did the player, so the player loses.
80
24
0
24
0
Returns: -80
2
19
0
6
0
Returns: -2
4
21
1
16
0
Returns: -4
68
17
0
27
0
Returns: -68
28
21
0
8
0
Returns: -28
34
17
0
20
0
Returns: 34
36
17
0
8
0
Returns: -36
2
17
0
23
0
Returns: -2
98
19
0
25
0
Returns: -98
54
21
0
26
0
Returns: -54
4
18
0
22
0
Returns: -4
78
17
0
28
0
Returns: -78
94
24
0
29
0
Returns: -94
6
22
0
17
0
Returns: 6
48
24
0
24
0
Returns: -48
6
26
0
23
0
Returns: -6
4
18
0
18
0
Returns: 0
78
21
1
22
0
Returns: -78
98
19
0
14
0
Returns: -98
10
22
0
15
0
Returns: 10
60
21
0
21
1
Returns: 90
10
21
0
21
1
Returns: 15
20
21
1
21
1
Returns: 0
100
25
0
25
0
Returns: -100
10
20
0
21
1
Returns: 15
32
19
0
13
0
Returns: -32
10
25
0
20
0
Returns: 10
10
22
0
20
0
Returns: 10
100
25
0
21
0
Returns: 100
10
23
0
21
0
Returns: 10
10
21
1
21
0
Returns: -10
10
21
1
10
0
Returns: -10
50
24
0
18
0
Returns: 50
10
22
0
22
0
Returns: -10
16
19
0
20
0
Returns: 16
60
21
1
21
1
Returns: 0
100
25
0
21
1
Returns: 150
10
17
0
17
0
Returns: 0
10
21
1
20
0
Returns: -10
50
20
0
19
0
Returns: -50
2
17
0
21
1
Returns: 3
10
20
0
20
0
Returns: 0
100
17
0
21
1
Returns: 150
2
17
0
21
0
Returns: 2
10
18
0
21
1
Returns: 15
100
21
0
21
1
Returns: 150
10
21
0
21
0
Returns: 0
50
26
0
20
0
Returns: 50
100
21
1
21
1
Returns: 0
10
21
1
21
1
Returns: 0
20
23
0
22
0
Returns: -20
10
23
0
20
0
Returns: 10
2
26
0
21
0
Returns: 2
10
24
0
19
0
Returns: 10
50
21
0
21
1
Returns: 75
2
23
0
22
0
Returns: -2
10
25
0
25
0
Returns: -10
10
17
0
21
1
Returns: 15
26
21
1
21
1
Returns: 0
10
23
0
18
0
Returns: 10
2
21
1
21
1
Returns: 0
20
20
0
19
0
Returns: -20
100
17
0
17
0
Returns: 0
100
22
0
21
0
Returns: 100
100
22
0
20
0
Returns: 100
10
21
0
22
0
Returns: -10
100
23
0
20
0
Returns: 100
100
21
0
21
0
Returns: 0
20
20
0
21
1
Returns: 30
2
22
0
21
0
Returns: 2
10
21
1
22
0
Returns: -10
100
19
0
22
0
Returns: -100