I hope you had fun building poker, Rito, if you had any trouble, no worries in this video.
I'm only going to go through task one because it's very long.
But in the next video, I'm going to go through the remaining tasks so you can choose which video to
watch, depending on where you got stuck.
So your first task was to create a function that returns a random card.
As always, it's going to be public static.
It returns string.
And the name of the function is random card.
It says nothing about parameters, so it's not going to take any and OK, there are 13 cards.
So inside the function, we need to get a random number between one and 13.
So what I'll do is I'll set double a random number is equal to Mathoura Random Times 13.
Remember that math, that random returns a random decimal between zero and less than one.
So if you multiply the result by 13, we can expect a decimal between zero and less than 13.
And in the second line, I'm going to add one to the random number range by setting random number plus
equals one.
And now we should expect the number to be in the range of one to less than 14.
And now we're going to set into equal to that random number, but as an integer as a whole, no.
And so this third line is going to cut off the decimal, which means our random number should now spend
the range of one to 13.
So far, this is nothing new because we did something very similar when we built Paradise Project in
the last section.
So we're done the first part of this function, the second part requires us the return, a card that
matches that random number.
And what you can do is get the string values from the cards, the text file, if you go to card text
in your file Explorer, I left you all 13 cards in the form of a string.
So what we can do is use a switch statement to compare their random number against 13 cases.
And in the event that a random number doesn't match any of our cases, we need to add a default case
because the function expect a string no matter what.
But obviously, this is never going to run because we know that our random number can only go from one
to 13.
In any case, in the event of a case match, we're going to return the right card.
So here we're going to return the card for case one, which would be Ace, I'm going to copy the ace
card to the right of the return key word, and then I can highlight all of this and press tab a few
times and bring this back.
And we just have to keep doing this 13 times.
If you feel like doing it with me, then by all means.
But if you want to skip ahead and fast forward, you can do that as well.
OK, now, even though this is never going to get called, Java doesn't know that and it's going to
give you an error because it's basically telling you, hey, in the event that a random number doesn't
match any of our cases, the default case needs to return a string value as well because the function
demands it.
So I'm going to return this shouldn't get called because they won't.
OK, that's all for task one, we're done, but it's good practice to always test your code before you
write any more.
So I'm going to call the function and print the return value from Main.
OK, I'll run my code.
And it returns a card, I'll know if my function works, if I keep returning a random card every time
I run it, and that is exactly the case.
In the next video, we're going to implement the remaining tasks.