Question: Write a program that simulates a game of 21 from the dealer's perspective. You do not have to add a player. Just focus on the

Write a program that simulates a game of 21 from the dealer's perspective. You do not have to add a player. Just focus on the dealer.

Have the dealer (computer) take two cards. Don't worry if the dealer gets the same card more than once; most dealers actually have a "shoe" that holds all their cards and they have multiple decks in the shoe at any time.

If the value of the cards adds up to 10 or less, draw another card.

Keep the dealer drawing cards until his total is 17 or higher.

Once the dealer gets to 17 or higher....

If the dealer goes over 21, he has busted.

If the dealer gets exactly 21, he has won.

If the dealer gets less than 21, he has lost.

You may reuse your card / card translator for this.

An Ace is worth 1 "point" if the other cards in the hand total more than 10. But an Ace is worth 10 points if the other cards in the hand when it is dealt total up to 10 or less.

Example Output:

Dealer first 2 cards: Ace of Diamonds and Two of Hearts

Dealer has 12

Dealer next card: Three of Clubs

Dealer has 15

Dealer next card: Ace of Hearts

Dealer has 16

Dealer next card: Five of Clubs

Dealer has 21. Dealer won.

5. Random Walk.

Simulate the random wandering of a person in a square street grid. You do NOT have to do any graphics.

This is somewhat like moth and bug from an earlier chapter. Assume the person is walking forward and backwards.

You can think of the person as walking on a number line. The person starts at 0, in the middle of the line.

Simulate the person taking 100 steps using a loop. You will randomly move the person one unit to the right or one unit to the left each time.

Print out each move. Then at the end, print out the person's location.

For example:

Person location = 0 Person moved 1 unit right to position 1 Person moved 1 unit right to position 2 Person moved 1 unit left to position 1 Person moved 1 unit left to position 0 Person moved 1 unit left to position -1

and so on for the 100 moves. Afte the last move, for example, print out the location on the number line like this:

Person location = -5

Use a random number to determine if the person moves right or left. You can use a number between 0 and 1 (so use rand.nextInt(2) to get the numbers 0 and 1). You could make 0 cause the person to move left and 1 to move right. This is just a suggestion; if you have another way to do this, that's fine.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!