Question

In: Computer Science

In Java please!! Your objective is to beat the dealer's hand without going over 21. Cards...

In Java please!!

Your objective is to beat the dealer's hand without going over 21. Cards dealt (randomly) are between 1 and 11. You receive 2 cards, are shown the total, and then are asked (in a loop) whether you want another card. You can request as many cards as you like, one at a time, but don't go over 21. (If you go over 21 it should not allow you any more cards and you lose) Determine the dealer's hand by generating a random number between 1 and 11 and adding 10 to it. Compare your hand with the dealer's hand and indicate who wins (dealer wins a draw)

Solutions

Expert Solution

import java.util.*;

public class BeatDealer {
        public static void main(String[] args) {
                Scanner scanner = new Scanner(System.in);
                String answer = "";
                int you = 0;
                System.out.println("Your Score " + you);
                int dealer = getRandomNumber(1, 11) + 10;
                while (true) {
                        System.out.print("Do you want another card? (y / n) ");
                        answer = scanner.nextLine();
                        
                        if (answer.equals("y")) {
                                int num = getRandomNumber(1, 11);
                                you+=num;
                                if (you <= 21) {     
                                        System.out.println("Your Score " + you);
                                } else {
                                        System.out.println("Your Score " + you);
                                        System.out.println("Your Score reached more than 21");
                                        System.out.println("Sorry! You lost the game");
                                        break;
                                }
                        } else {
                                if (you > dealer) {
                                        System.out.println("You won the game, "+ "You - " +you+ " Dealer - "+dealer);
                                } else if(you == dealer) {
                                        System.out.println("Draw, "+ "You - " +you+ " Dealer - "+dealer);
                                } else {
                                        System.out.println("Dealer won the game, "+ "You - " +you+ " Dealer - "+dealer);
                                }
                                break;
                        }
                }
        }

        static int getRandomNumber(int min, int max) {  
                return (int) ((Math.random() * (max - min)) + min);
        }
}

Related Solutions

----------USING JAVA----------- Your objective is to beat the dealer's hand without going over 21. Cards dealt...
----------USING JAVA----------- Your objective is to beat the dealer's hand without going over 21. Cards dealt (randomly) are between 1 and 11. You receive 2 cards, are shown the total, and then are asked (in a loop) whether you want another card. You can request as many cards as you like, one at a time, but don't go over 21. (If you go over 21 it should not allow you any more cards and you lose) Determine the dealer's hand...
A bridge hand is found by takinf 13 cards at random and without replacement from a...
A bridge hand is found by takinf 13 cards at random and without replacement from a deck of 52 playing cards. Find the probability of drawing each of the following hands. (a) One in which there are 5 spades, 4 hearts, 3 diamonds and 1club. (b) One in which there are 5 spades, 4 hearts, 2 diamonds and 1 club. (c) One in which there are 5 spades, 4 hearts, 2 diamond, and 3 clubs. (d) Suppose you are dealt...
5. A hand of five cards is drawn without replacement from a standard deck. (a) Compute...
5. A hand of five cards is drawn without replacement from a standard deck. (a) Compute the probability that the hand contains both the king of hearts and the king of spades. (b) Let X = the number of kings in the hand. Compute the expected value E(X). Hint: consider certain random variables X1, . . . , X4. (c) Let Y = the number of “face” cards in the hand. Given is that E(Y ) = 15/13. Find the...
An adventurous archaeologist crosses between two rock cliffs by slowly going hand over hand along a...
An adventurous archaeologist crosses between two rock cliffs by slowly going hand over hand along a rope stretched between the cliffs. He stops to rest at the middle of the rope. The rope will break if the tension in it exceeds 3.00×104 N. Our hero’s mass is 85.0 kg. Part A: If the angle θ is 13.0 ∘, find the tension in the rope (answer in form T= ? N. Part B: What is the smallest value the angle θ...
Java: Simple 21 Game (Blackjack) In this game, the dealer deals two "cards" to each player,...
Java: Simple 21 Game (Blackjack) In this game, the dealer deals two "cards" to each player, one hidden, so that only the player who gets it knows what it is, and one face up, so that everyone can see it. There are four players: one human player (user) and three computer players. The players take turns requesting cards, trying to get as close to 21 as possible, but not going over 21. A player may pass. Once a player has...
The answers previously provided are all over the place. Without Excel Please. - - Your sister...
The answers previously provided are all over the place. Without Excel Please. - - Your sister has estimated that the maintenance costs on the “slightly used” car she just purchased will be $500 in the first year. She anticipates that this cost will increase by $150 each year. She wants to set aside enough money today to cover all anticipated maintenance costs for the 10 years that she plans to own the car. How much should she deposit today in...
case study please net hand writing if you are going to post a picture this is...
case study please net hand writing if you are going to post a picture this is all the info that was given to me Scenario #1: Older Adults: Mrs. Alice Green, a 78 year old female, has had a bone density scan as part of a regular physical check and has been told that she has severe osteoporosis. Her primary care health practitioner has ordered a new medication that is supposed to maintain bone mass in clients with osteoporosis. Mrs....
December 21, 2012: Are we all going to die? Section: ____________ Written by: Jeremy Jones Over...
December 21, 2012: Are we all going to die? Section: ____________ Written by: Jeremy Jones Over the past few years, websites, books, and even a big blockbuster movie have popped up concerning the ancient Mayan "prediction" that the world will end on December 21, 2012. It is true that the 13th bak'tun of the Mayan calendar will end on December 21, 2012. So what?, the 12th month of the modern calendar ends on December 31 every year. However, the end...
JAVA PLEASE In this project, we are going to build a tiny database organized as a...
JAVA PLEASE In this project, we are going to build a tiny database organized as a singly linked list for storing and retrieving the information of a group of products on sale. The information of each product includes the following items: Product ID, Name, Seller, Quantity In Stock, Average Shipping Time, Original Price, Current Price. We assume that a node in the linked list should be defined by the following class. class Product {      long ID;      String name;...
Please solve without the use of excel by discounting the cash flows "by-hand". Find the FV...
Please solve without the use of excel by discounting the cash flows "by-hand". Find the FV of $10,000 33 years in the future if the opportunity cost rate is 8% (use Excel formulas and basic PV/FV techniques). Find the PV of $1,000,000 to be delivered in 16 years if the opportunity cost rate is 7% (use Excel formulas and basic PV/FV techniques). Would you prefer the following (you can use just formulas for this problem): An ordinary annuity where you...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT