Question

******IN JAVA***** Your objective is to beat the dealer's hand without going over 21. Cards dealt...

******IN 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 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)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

SOLUTION-
I have solve the problem in Java code with comments and screenshot for easy understanding :)

CODE-

//java code
import java.util.*;
//main class
public class Main {
//main method
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String answer = "";
int you = 0;
System.out.println("Your Score " + you); //show score
int dealer = getRandomNumber(1, 11) + 10; //dealer calcualtion
while (true) //loop until it get false
{
System.out.print("Do you want another card? (y / n) "); //ask for user to play y or n
answer = scanner.nextLine(); //reads
if (answer.equals("y")) //if yes (y)
{
int num = getRandomNumber(1, 11); //call random function and give random number
you+=num;   
if (you <= 21) //if number is less than 21
{   
System.out.println("Your Score " + you); //print score
}
else //else part
{
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 //show result who won or draw
{
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;
}
}
}
//function getRandomNumber
static int getRandomNumber(int min, int max)
{
return (int) ((Math.random() * (max - min)) + min);
}
}


SCREENSHOT-

8 9 score Main.java 1 1/java code 2 import java.util.*; 3 //main class 4. public class Main { 5 //main method 6 public static

27 System.out.println(Your Score reached more than 21); 28 System.out.println(Sorry! You lost the game); 29 break; 30 } 3

Your Score 0 Do you want another card? (y / n) y Your Score 3 Do you want another card? (y / n) y Your Score 8 Do you want an


IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I WILL SOLVE IT FOR YOU:)
----------------PLEASE RATE THE ANSWER-----------THANK YOU!!!!!!!!----------

Add a comment
Know the answer?
Add Answer to:
******IN JAVA***** Your objective is to beat the dealer's hand without going over 21. Cards dealt...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a simplified Blackjack game using the Deck and Card classes (download the attached files to...

    Create a simplified Blackjack game using the Deck and Card classes (download the attached files to start).  There is also a "TestCard" class that creates a Deck and runs some simple code. You may choose to use this file to help you get started with your game program. 1) Deal 2 cards to the "player" and 2 cards to the "dealer".  Print both the player's cards, print one of the dealer's cards. Print the total value of the player's hand. 2) Ask...

  • programming language c++ its a project if anyone can help me it's will be appreciated thnk...

    programming language c++ its a project if anyone can help me it's will be appreciated thnk u. u have to create a code based on the information im giving u you can do it in 1 or 2 day i can wait 1:26 #WW 2.53% Example: A user starts with 1000 points. Game #1 - user chooses to risk 200 points. User wins game (beats the dealer). User now has 1200 points. Game #2 - user chooses to risk 500...

  • programming language c++ programming language c++ 1:25 #WW # 53% You may, if you wish, work...

    programming language c++ programming language c++ 1:25 #WW # 53% You may, if you wish, work in pairs; this means that a submission may have 2 names attached but those 2 people must have worked on the project. No free rides! The way to submit the program to me is as follows: put the entire program (main and any other functions) into a single compile. Compile it to be sure that you have the correct set of #include statements and...

  • Using Java You are helping a corporation create a new system for keeping track of casinos...

    Using Java You are helping a corporation create a new system for keeping track of casinos and customers. The system will be able to record and modify customer and casino information. It will also be able to simulate games in the casino. Customer-specific requirements You can create new customers All new customers have a new customerID assigned to them, starting with 1 for the first, 2 for the second, 3 for the third, ect. New customers have names and monetary...

  • You are helping a corporation create a new system for keeping track of casinos and customers....

    You are helping a corporation create a new system for keeping track of casinos and customers. The system will be able to record and modify customer and casino information. It will also be able to simulate games in the casino. You may complete this project individually or in a group of no more than 2 other people. Requirements do not change if you choose to complete the project individually or as part of a group. Customer-specific requirements You can create...

  • MATLAB code help! Function Name: jackSparrow Inputs: 1. (double) A 1x2 vector describing your hand 2....

    MATLAB code help! Function Name: jackSparrow Inputs: 1. (double) A 1x2 vector describing your hand 2. (double) A 1x2 vector describing Jack Sparrow's hand 3. (double) A vector with the next cards to be drawn from the deck Outputs: 1. (char) A description of the game outcome Background: You're out at sea with the infamous Jack Sparrow, and it's a pretty calm day. Without anything better to do, Jack Sparrow challenges you to his favorite card game: BlackJack (Sparrow edition)...

  • Note: Please write the Pseudocode using Arrays method in Java language. Program 2 (40%); For this...

    Note: Please write the Pseudocode using Arrays method in Java language. Program 2 (40%); For this assignment, we're going to make a game. Imagine you initially start with a random "hand" of two cards (values 2-9). Your goal is to continue to add to your hand until the sum of the cards is between 21 25, at which point youu win. Further, if you hold 5 cards, you win. However, if you exceed a sum of 25, you lose. Admittedly,...

  • Using C++ Create a Blackjack program with the following features: Single player game against the dealer....

    Using C++ Create a Blackjack program with the following features: Single player game against the dealer. Numbered cards count as the number they represent (example: 2 of any suit counts as 2) except the Aces which can count as either 1 or 11, at the discretion of the player holding the card. Face cards count as 10. Player starts with $500. Player places bet before being dealt a card in a new game. New game: Deal 2 cards to each...

  • Please write the program in python: 3. Design and implement a simulation of the game of...

    Please write the program in python: 3. Design and implement a simulation of the game of volleyball. Normal volleyball is played like racquetball, in that a team can only score points when it is serving. Games are played to 15, but must be won by at least two points. 7. Craps is a dice game played at many casinos. A player rolls a pair of normal six-sided dice. If the initial roll is 2, 3, or 12, the player loses....

  • Write a Java program to simulate Blackjack. The program should be as basic as possible while...

    Write a Java program to simulate Blackjack. The program should be as basic as possible while following the rules below. Thanks a. There is one deck of cards b. Cards are drawn randomly using (Shuffle() method) c. The value of a hand is computed by adding the values of the cards in hand d. The value of a numeric card such as four is its numerical value e. The value of a face card is 10 f. Ace is either...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT