Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,210 --> 00:00:02,530
There were two parts of the building, blackjack in part.
2
00:00:02,550 --> 00:00:04,770
One was to set up the logic for starting the game.
3
00:00:06,840 --> 00:00:10,960
The first task was to make a function that returns a random number between one and 13.
4
00:00:11,580 --> 00:00:13,770
Like always, it's going to be public static.
5
00:00:17,260 --> 00:00:18,610
It returns an integer.
6
00:00:22,040 --> 00:00:26,730
The function is called draw random card, and it doesn't take any parameters.
7
00:00:27,440 --> 00:00:31,790
Now, returning a random number between a certain range is something we've done a million times.
8
00:00:35,900 --> 00:00:40,070
First, we use Mathurin, him to get a random decimal from zero to less than one.
9
00:00:42,860 --> 00:00:47,630
And multiplying the result by 13 is going to scale the range from zero to less than 13.
10
00:00:49,580 --> 00:00:53,810
We can add one to the random number to scale the range from one to less than 14.
11
00:00:54,840 --> 00:01:00,290
And then typecasting, double to end cuts off the decimal and returns a whole number from one to 13,
12
00:01:00,900 --> 00:01:02,190
a fairly simple task.
13
00:01:08,370 --> 00:01:13,440
The second task is to make a function that returns a string drawing of the card, as always, its public
14
00:01:13,440 --> 00:01:14,010
static.
15
00:01:18,000 --> 00:01:19,620
And this one returns a string.
16
00:01:31,080 --> 00:01:34,650
And it takes one parameter, an integer that represents a card number.
17
00:01:36,090 --> 00:01:40,080
When you call this function, it's going to receive an integer value and we have to match that integer
18
00:01:40,080 --> 00:01:45,780
value to a card, so we'll use a switch statement to compare the card number against the list of 13
19
00:01:45,780 --> 00:01:46,410
cards.
20
00:02:15,770 --> 00:02:17,960
And don't forget the usual default case.
21
00:02:19,880 --> 00:02:24,350
Because in the event that a random number doesn't match any of our cases, we need the default case
22
00:02:24,350 --> 00:02:25,950
to return a string value as well.
23
00:02:26,630 --> 00:02:29,600
It's simply going to return a string that says not possible.
24
00:02:35,200 --> 00:02:41,470
And for each case, I'm going to return the corresponding cards drink, this is a long process, as
25
00:02:41,470 --> 00:02:42,130
you saw in poker.
26
00:02:42,140 --> 00:02:46,510
Orito So I'm going to fast forward the video because I trust that by now you should know how to do it.
27
00:02:48,930 --> 00:02:51,420
OK, that's over, I'm going to do some cleaning up.
28
00:03:03,000 --> 00:03:09,770
And task three, this one tells us that the user needs to press enter to start the game, some not Eskandar
29
00:03:09,790 --> 00:03:12,000
next line after putting the welcome messages.
30
00:03:15,040 --> 00:03:20,350
And notice that I declared scanner at the level of the class, instead of declaring it in the main method,
31
00:03:20,870 --> 00:03:22,240
you'll find out one part two.
32
00:03:22,240 --> 00:03:26,500
But that doesn't matter because we declared our scanner variable at the level of the class, which means
33
00:03:26,500 --> 00:03:31,900
we can access it from anywhere inside the class section or in our code for now, because we've written
34
00:03:31,900 --> 00:03:32,730
so much.
35
00:03:32,740 --> 00:03:34,180
Let's make sure everything is OK.
36
00:03:50,530 --> 00:03:52,660
OK, so far, nothing interesting.
37
00:03:52,810 --> 00:03:55,810
Now we need to move on to task for to test our function.
38
00:03:58,550 --> 00:04:03,800
When the game starts, the player gets two cards face up so we can use draw a random card to get two
39
00:04:03,800 --> 00:04:04,850
random cards.
40
00:04:17,329 --> 00:04:22,340
Now, each function call is going to return a random integer value between one and 13 into the next
41
00:04:22,340 --> 00:04:24,770
step is to print the string representation of each card.
42
00:04:29,630 --> 00:04:32,240
What I'll do is I'll print you get a new line.
43
00:04:36,340 --> 00:04:39,730
And we can use card strength to return a string drawing of the first card number.
44
00:04:49,760 --> 00:04:50,910
We'll copy this as well.
45
00:04:56,480 --> 00:04:58,730
And connect a string drawing of the second card.
46
00:05:08,810 --> 00:05:09,890
Let's run our code.
47
00:05:17,320 --> 00:05:18,850
And I got a seven and a two.
48
00:05:26,200 --> 00:05:31,480
OK, task five, which is to print the player's hand value, in other words, we need to add up the
49
00:05:31,480 --> 00:05:33,090
value of each card into a total.
50
00:05:33,640 --> 00:05:35,530
So int total.
51
00:05:37,650 --> 00:05:41,430
Is equal to the value of card one plus the value of card to.
52
00:05:50,930 --> 00:05:52,010
Your total is.
53
00:05:56,240 --> 00:05:58,270
Connecting the players total hand value.
54
00:06:04,440 --> 00:06:05,910
Easy right Netrunner code.
55
00:06:16,030 --> 00:06:21,640
Remember that face cards, Jack Queen King should have values of 10, but currently your code treats
56
00:06:21,640 --> 00:06:24,400
Jack Queen and King as 11, 12 and 13.
57
00:06:25,060 --> 00:06:28,540
In this case, the queen is a 12 and three plus 12 is 15.
58
00:06:29,560 --> 00:06:35,170
In the instructions, I give you a hint and it was to use my thought men, because if you look at the
59
00:06:35,170 --> 00:06:39,370
Java documentation, there are four versions of the main function we can use.
60
00:06:39,370 --> 00:06:43,090
Map thought meant to take to integer values and return the smaller of the two.
61
00:06:46,630 --> 00:06:52,030
So here we can use my Damon to get the smaller value between the card number and 10, we'll get the
62
00:06:52,030 --> 00:06:58,780
smaller value between a card one and 10 plus Matt Damon getting the smaller value between card two and
63
00:06:58,780 --> 00:06:59,110
10.
64
00:07:03,860 --> 00:07:04,970
If you run this code.
65
00:07:12,400 --> 00:07:17,380
It's clear that JAV accounts face value this 10 because seven plus 10 is 17.
66
00:07:17,860 --> 00:07:18,970
Think about what happened.
67
00:07:20,690 --> 00:07:22,220
My first card was a seven.
68
00:07:25,020 --> 00:07:27,540
And the minimum value between seven and 10 is seven.
69
00:07:31,070 --> 00:07:36,590
And my second card was a king, which is 13, and the minimum value between 13 and 10 is 10.
70
00:07:37,280 --> 00:07:43,190
In essence, what Matt Damon is doing is it's reducing any card value that is 11, 12 or 13, back down
71
00:07:43,190 --> 00:07:43,670
to 10.
72
00:07:45,320 --> 00:07:50,660
And so from an animation perspective, the two arguments are the card number intent, if the card number
73
00:07:50,660 --> 00:07:52,850
is bigger than 10 men returns 10.
74
00:07:54,960 --> 00:07:58,470
If the card number is smaller than 10 million returns, the card number.
75
00:08:00,010 --> 00:08:03,550
And if the card no intent or equal means simply returns 10.
76
00:08:05,510 --> 00:08:09,860
Like men, there are many other built in functions that make our coding lives easier.
77
00:08:10,190 --> 00:08:11,900
It's up to you to look them up.
78
00:08:14,620 --> 00:08:16,300
And now the dealer gets two cards as well.
79
00:08:16,480 --> 00:08:18,800
This is going to follow a very similar process.
80
00:08:19,180 --> 00:08:24,700
Once again, we use draw random card to get two random cards, but this time for the dealer, dealer,
81
00:08:24,700 --> 00:08:26,800
card one and dealer card to.
82
00:08:33,260 --> 00:08:38,690
Each function call is going to return a random integer value between one in 13 and like before we're
83
00:08:38,690 --> 00:08:41,150
going to print the string representation of each value.
84
00:08:41,750 --> 00:08:43,039
So I'll print a new line.
85
00:08:46,710 --> 00:08:48,360
The dealer shows new line.
86
00:08:51,290 --> 00:08:52,940
And print the first card string.
87
00:08:56,880 --> 00:08:58,170
Followed by a new line.
88
00:09:09,370 --> 00:09:14,290
And if you remember, the dealer's cards needs to be facing down or his second card, for that matter,
89
00:09:14,830 --> 00:09:19,420
so inside your workbook, I left you a function called Face Down that returns a face down card.
90
00:09:26,980 --> 00:09:31,150
So we're going to call this function and print the return value, because we don't want to show the
91
00:09:31,150 --> 00:09:32,530
dealer second card just yet.
92
00:09:39,500 --> 00:09:43,820
And just like before, we're going to calculate the dealer's hand value with simply odds, their first
93
00:09:43,820 --> 00:09:44,900
card by the second.
94
00:09:45,500 --> 00:09:49,700
And remember, we're going to use my thumb and to make sure that face values don't get counted as 11,
95
00:09:49,700 --> 00:09:50,630
12 or 13.
96
00:10:06,250 --> 00:10:10,330
OK, so we have the dealer's total, but until the game actually starts, we're going to hide it.
97
00:10:10,730 --> 00:10:11,770
So here, I'll print.
98
00:10:11,800 --> 00:10:13,270
The dealer's total is hidden.
99
00:10:17,310 --> 00:10:21,390
All right, that's all for part one, it's time to run the code one final time.
100
00:10:40,470 --> 00:10:43,710
And to no surprise, I get two cards, so does the dealer.
101
00:10:45,330 --> 00:10:50,220
But instead of printing their second card, we're printing a face down card because we don't intend
102
00:10:50,220 --> 00:10:51,420
on showing it just yet.
103
00:10:51,810 --> 00:10:52,880
All right, that is all.
104
00:10:52,920 --> 00:10:54,480
I'll see you in part two.
10058
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.