Java Bootcamp – Workbooks and Challenges
)}

# Pokerito (it's almost Poker!)

Pokerito is like Poker, but the rules are a lot simpler.

• The dealer will give you one card

• and the computer one card.

• Then, the dealer will draw five cards (the river).

• The player with the most river matches wins. If the matches are equal, everyone's a winner!

Final Output:

## Launch the workbook

From `Java Bootcamp Resources` -> `Module 1` -> `5. Loops`, open Pokerito.

Create the function: `randomCard`.

``````    /**
* Function name -- randomCard
* @return (String)
*
* Inside the function:
*   1. Gets a random number between 1 and 13.
*   2. Returns a card that matches the random number.
*/
``````

Inside your folder, there's a `cards.txt` file. There, you can find all the cards in `String` format.

``````           1﻿:      "   _____\n"﻿+
"  |A _  |\n"﻿+
"  | ( ) |\n"﻿+
"  |(_'_)|\n"﻿+
"  |  |  |\n"﻿+
"  |____V|\n"﻿;
...``````

There are 13 cards that go from Ace (1) to King (13). Use `switch` to return a card that matches the random number.

``````    /**
* Function name -- randomCard
* @return (String)
*
* Inside the function:
*   1. Gets a random number between 1 and 13.
*   2. Returns a card that matches the random number. <-----
*/
``````

Call the function and print the return value.

Keep running your function. If it gives you a random card each time, then you're good to go!

Start the game by explaining the rules.

`Let's play Pokerito. Type anything when you're ready.`

`It's like Poker, but a lot simpler.`

` - There are two players, you and the computer.`

` - The dealer will give each player one card.`

` - Then, the dealer will draw five cards (the river)`

` - The player with the most river matches wins!`

` - If the matches are equal, everyone's a winner!`

` - Ready? Type anything if you are.`

Once the user "is ready", present them with a card. Also, show them the computer's card.

``````       /*Task 3: Present the user with a card

<show card>
<new line>
Here's the computer's card:
<show computer's card>

*/``````

Print: `Now, the dealer will draw five cards. Press enter to continue.`

Use a `for` loop to draw a card every time the user presses enter. You must draw a total of 5 cards and print the order of each one.

1. Count how many times your card matches with the river.

2. Count how many times the computer's card matches with the river.

Then:

• print: `Your number of matches: <yourMatches>`

• print: `Computer number of matches: <computerMatches>`

If you have more matches, print: `You win!`. If the computer has more matches, print: `The computer wins!`. If the matches are equal, print: `everyone wins!`.

Example:

``````Here's your card:
_____
|﻿9    |
|o o o|
|o o o|
|o o o|
|____9|

Here's the computer's card:
_____
|7    |
| o o |
﻿  |o o o|
| o o |
|____7|``````
``Now, the dealer will draw five cards. Press enter to continue﻿.``
``````Card 1

_____
|7    |
﻿| o o |
|o o o|
| o o |
|____7|

Card 2

_____
﻿|6    |
| o o |
| o o |
| o o |
|____6|

Card 3

_____
﻿  |6    |
| o o |
| o o |
| o o |
|____6|

Card 4

_____
|7    |
﻿| o o |
|o o o|
| o o |
|____7|

Card 5

_____
|2 ﻿   |
|  o  |
|     |
|  o  |
|____Z|``````
``````Your number of matches: 0
Computer number of matches: 2
Computer wins!``````

## Good luck!

##### Related Course: The Complete Spring Boot Development Bootcamp – Become a Java Web Developer

Feedback Summary
4.7
43 students
5

91%
4

2%
3

0%
2

0%
1

7%
Written Reviews
There are no written reviews yet.