1 00:00:00,520 --> 00:00:05,270 I hope you had fun building poker, Rito, if you had any trouble, no worries in this video. 2 00:00:05,300 --> 00:00:07,820 I'm only going to go through task one because it's very long. 3 00:00:08,240 --> 00:00:12,560 But in the next video, I'm going to go through the remaining tasks so you can choose which video to 4 00:00:12,560 --> 00:00:14,720 watch, depending on where you got stuck. 5 00:00:16,730 --> 00:00:20,090 So your first task was to create a function that returns a random card. 6 00:00:20,120 --> 00:00:22,730 As always, it's going to be public static. 7 00:00:25,460 --> 00:00:26,780 It returns string. 8 00:00:29,030 --> 00:00:31,370 And the name of the function is random card. 9 00:00:33,480 --> 00:00:39,420 It says nothing about parameters, so it's not going to take any and OK, there are 13 cards. 10 00:00:39,420 --> 00:00:43,470 So inside the function, we need to get a random number between one and 13. 11 00:00:44,530 --> 00:00:50,350 So what I'll do is I'll set double a random number is equal to Mathoura Random Times 13. 12 00:00:57,410 --> 00:01:02,190 Remember that math, that random returns a random decimal between zero and less than one. 13 00:01:02,720 --> 00:01:09,050 So if you multiply the result by 13, we can expect a decimal between zero and less than 13. 14 00:01:10,280 --> 00:01:15,730 And in the second line, I'm going to add one to the random number range by setting random number plus 15 00:01:15,740 --> 00:01:16,430 equals one. 16 00:01:17,560 --> 00:01:21,430 And now we should expect the number to be in the range of one to less than 14. 17 00:01:25,900 --> 00:01:30,220 And now we're going to set into equal to that random number, but as an integer as a whole, no. 18 00:01:36,880 --> 00:01:41,410 And so this third line is going to cut off the decimal, which means our random number should now spend 19 00:01:41,410 --> 00:01:43,330 the range of one to 13. 20 00:01:44,500 --> 00:01:49,270 So far, this is nothing new because we did something very similar when we built Paradise Project in 21 00:01:49,270 --> 00:01:50,140 the last section. 22 00:01:52,400 --> 00:01:56,840 So we're done the first part of this function, the second part requires us the return, a card that 23 00:01:56,840 --> 00:01:58,580 matches that random number. 24 00:02:00,630 --> 00:02:06,120 And what you can do is get the string values from the cards, the text file, if you go to card text 25 00:02:06,120 --> 00:02:09,990 in your file Explorer, I left you all 13 cards in the form of a string. 26 00:02:13,450 --> 00:02:18,880 So what we can do is use a switch statement to compare their random number against 13 cases. 27 00:02:57,420 --> 00:03:02,370 And in the event that a random number doesn't match any of our cases, we need to add a default case 28 00:03:02,850 --> 00:03:05,250 because the function expect a string no matter what. 29 00:03:07,380 --> 00:03:11,730 But obviously, this is never going to run because we know that our random number can only go from one 30 00:03:11,730 --> 00:03:12,420 to 13. 31 00:03:14,360 --> 00:03:18,020 In any case, in the event of a case match, we're going to return the right card. 32 00:03:22,990 --> 00:03:27,790 So here we're going to return the card for case one, which would be Ace, I'm going to copy the ace 33 00:03:27,790 --> 00:03:32,620 card to the right of the return key word, and then I can highlight all of this and press tab a few 34 00:03:32,620 --> 00:03:34,210 times and bring this back. 35 00:03:35,350 --> 00:03:37,780 And we just have to keep doing this 13 times. 36 00:03:37,780 --> 00:03:40,390 If you feel like doing it with me, then by all means. 37 00:03:40,810 --> 00:03:44,070 But if you want to skip ahead and fast forward, you can do that as well. 38 00:07:16,350 --> 00:07:20,370 OK, now, even though this is never going to get called, Java doesn't know that and it's going to 39 00:07:20,370 --> 00:07:25,800 give you an error because it's basically telling you, hey, in the event that a random number doesn't 40 00:07:25,800 --> 00:07:31,140 match any of our cases, the default case needs to return a string value as well because the function 41 00:07:31,140 --> 00:07:31,860 demands it. 42 00:07:32,970 --> 00:07:36,900 So I'm going to return this shouldn't get called because they won't. 43 00:07:45,490 --> 00:07:51,100 OK, that's all for task one, we're done, but it's good practice to always test your code before you 44 00:07:51,100 --> 00:07:51,760 write any more. 45 00:07:51,760 --> 00:07:54,820 So I'm going to call the function and print the return value from Main. 46 00:08:01,810 --> 00:08:03,190 OK, I'll run my code. 47 00:08:15,670 --> 00:08:21,040 And it returns a card, I'll know if my function works, if I keep returning a random card every time 48 00:08:21,040 --> 00:08:24,160 I run it, and that is exactly the case. 49 00:08:24,610 --> 00:08:27,550 In the next video, we're going to implement the remaining tasks.