Question

In: Computer Science

Your hardcopy submission will consist of these two things: Source code (your java file). Screenshot of...

Your hardcopy submission will consist of these two things:

  1. Source code (your java file).
  2. Screenshot of Eclipse showing output of program. (JPG or PNG format only)

Write a program to play the game of Stud Black Jack. This is like regular Black Jack except each player gets 2 cards only and cannot draw additional cards.

Create an array of 52 integers. Initialize the array with the values 0-51 (each value representing a card in a deck of cards) in your main method. Pass the array as a parameter to a method to shuffle the array. Use this prototype:

public static void ShuffleDeck (int [] deck);

Each of the values 0-51 will represent playing card. Text descriptions of each card use the following rules (as discussed in class).

Cards 0-12 are spades.

Cards 13-25 are hearts.

Cards 26-37 are clubs.

Cards 38-51 are diamonds.

Card 0 is an Ace. Card 1 is a Two. Card 2 is a Three and so on. Card 10 is a jack. Card 11 is a queen. Card 12 is a king.

When printing text descriptions of each card, us the following format:

value-of-card “ of” suit-of-card

For example:

Ace of Spades

Two of Diamonds

After the array is shuffled, the first 2 cards (from the top of the deck) go to the dealer and the next 2 cards go to the player. Store the dealer and player cards in separate. For example, use the following definitions:

int dealerHand [], playerHand[]; // references to 2 arrays

Print on the screen a text description of the 2 cards the dealer has and the 2 cards the player has. In addition, print a line indicating the value of the hand. For example:

*****Dealer*****

Ace of Spades

Two of Diamonds

[value = 13]

*****Player*****

Nine of Hearts

Three of Clubs

[value = 12]

Dealer won this round.

Create a method that takes an array of integers and computes and returns the value of the cards in the array. You code must handle Ace’s properly in the calculation as discussed in class. Use this prototype:

// Input is array of 2

int valueOfHand (int []hand);

Finally, print a message indicating who won the game.

Next, prompt the player if they want to play again (y/n). If so, repeat the above with the exception that you do not need to shuffle the deck unless there are less than 4 cards left in the deck in which case you need to shuffle again before dealing the next round.

Put your name, the class (COSC 1336) and the title of the assignment in comments at the top of the program.

Run your program.

Solutions

Expert Solution

BlackJack Game ( JAVA )


import java.util.*;
public class Main
{
   public static void main(String[] args) {
   Scanner sc = new Scanner(System.in);
   while(true)
   {
   int deck[] = new int[52];
   for(int i=0;i<52;i++)
   {
   deck[i]=i;
   }
   ShuffleDeck (deck);
   for(int i=0;i<52;i++)
   {
   //System.out.print(deck[i] + " ");
   }
  
   int dealerHand [] = {deck[0] , deck[1]};
   int playerHand[] = {deck[2] , deck[3]};
   System.out.println("********Dealer********");
   int valDealer = valueOfHand(dealerHand);
   System.out.println("********Player********");
   int valPlayer = valueOfHand(playerHand);
   if(valPlayer>valDealer)
   System.out.println("Player won this round " );
   else if(valPlayer<valDealer)
   System.out.println("Dealer won this round " );
   else
   System.out.println("Draw " );
   System.out.println("Do you want to play again y/n" );
   char ch = sc.next().charAt(0);
   if(ch == 'n' || ch == 'N')
   break;
   }
  
  
   }
  
   public static void ShuffleDeck (int [] deck)
   {
   Random rgen = new Random();
   for (int i=0; i<deck.length; i++) {
       int randomPosition = rgen.nextInt(deck.length);
       int temp = deck[i];
       deck[i] = deck[randomPosition];
       deck[randomPosition] = temp;
       }
   }
  
   public static int valueOfHand (int []hand )
   {
   int sum = 0;
   for(int i=0;i<hand.length;i++)
   {
   int val = hand[i];
   int type = val/13;
   int number = val%13;
   String num ="";
   String face = "";
   switch(type)
   {
   case 0:
   face = "spades";
   break;
   case 1:
   face = "hearts";
   break;
   case 2:
   face = "clubs";
   break;
   case 3:
   face = "diamonds";
   break;
   }
   switch(number)
   {
   case 0:
   num = "Ace";
   break;
   case 1:
   num = "Two";
   break;
   case 2:
   num = "Three";
   break;
   case 3:
   num = "Four";
   break;
   case 4:
   num = "Five";
   break;
   case 5:
   num = "Six";
   break;
   case 6:
   num = "Seven";
   break;
   case 7:
   num = "Eight";
   break;
   case 8:
   num = "Nine";
   break;
   case 9:
   num = "Ten";
   break;
   case 10:
   num = "Jack";
   break;
   case 11:
   num = "Queen";
   break;
   case 12:
   num = "King";
   break;
  
   }
  
   System.out.println(num + " of " + face);
   if(number>=1 && number<=9)
   sum+=number+1;
   else
   sum+=11;
   }
   System.out.println("[value = " + sum + "]");
   return sum;
   }
}


Related Solutions

Directly copy the source code and paste into the Word file. Screenshot of running result must...
Directly copy the source code and paste into the Word file. Screenshot of running result must be presented. 1. (20 points) Write the “Hello, world!” program. 2. (30 points) Write a program to calculate the sum from -5 to10. Use the for loop to do the calculation. 3. (20 points) Write a complete C++ program that asks the user to enter the necessary information about the cylinder, calculate the volume in a function (named as calculate_vol, using reference to pass...
Can you provide source code in Java that 1. accepts a two-way acceptor via file; 2....
Can you provide source code in Java that 1. accepts a two-way acceptor via file; 2. and validate if the input string is part of the language
Write in java The submission utility will test your code against a different input than the...
Write in java The submission utility will test your code against a different input than the sample given. When you're finished, upload all of your .java files to Blackboard. Grading: Each problem will be graded as follows: 0 pts: no submission 1 pts: submitted, but didn't compile 2 pts: compiled, but didn't produce the right output 5 pts: compiled and produced the right output Problem 1: "Letter index" Write a program that inputs a word and an unknown number of...
3.) Analyze the Java Program LinkRotator RUN the code and add the screenshot of the window...
3.) Analyze the Java Program LinkRotator RUN the code and add the screenshot of the window and output. Describe what code change you would make if you wanted each link to be displayed for 2.5 seconds. _______________________________________________________________ Below is the "LinkRotator" java program: 1: package com.java24hours; 2: 3: import java.awt.*; 4: import java.awt.event.*; 5: import java.io.*; 6: import javax.swing.*; 7: import java.net.*; 8:    9: public class LinkRotator extends JFrame 10: implements Runnable, ActionListener { 11: 12: String[] pageTitle =...
Below is my source code for file merging. when i run the code my merged file...
Below is my source code for file merging. when i run the code my merged file is blank and it never shows merging complete prompt. i dont see any errors or why my code would be causing this. i saved both files with male names and female names in the same location my source code is in as a rtf #include #include #include using namespace std; int main() { ifstream inFile1; ifstream inFile2; ofstream outFile1; int mClientNumber, fClientNumber; string mClientName;...
Create a java program that has a code file with main() in it and another code...
Create a java program that has a code file with main() in it and another code file with a separate class. You will be creating objects of the class in the running program, just as the chapter example creates objects of the Account class. Your system handles employee records and processes payroll for them. Create a class called Employee that holds the following information: first name, last name, monthly salary, and sales bonus. The class should have all the gets...
Name your source code file sh.c Write your own simple shell. Your shell should prompt the...
Name your source code file sh.c Write your own simple shell. Your shell should prompt the user for a command, run it, then prompt the user for their next command. If the user types "exit", then the shell should terminate. The shell should ignore Ctrl-C. Inside the attached parse.h header file, there is a parse function that you can use to split up the command line into separate strings. Recall that execvp accepts two arguments: the name of the command,...
I NEED IT PRINT IN THIS FORM JAVA How is a Java source file executed? 1....
I NEED IT PRINT IN THIS FORM JAVA How is a Java source file executed? 1. It is compiled and runs natively 2. It is interpreted but not compiled 3. It is compiled into byte code and executed by the Java Virtual Machine 4. It is magic Please enter your answer 1 Sorry that answer is not correct. The correct answer is 3 Correct output: How is a Java source file executed? 1. It is compiled and runs natively 2....
This is a programming assignment!!! Start with the Assignment3.java source code posted to Canvas. This code...
This is a programming assignment!!! Start with the Assignment3.java source code posted to Canvas. This code outputs the programmer’s name , prompts the user to enter two numbers (integers) and outputs their sum. Note: When you run the program, it expects you to enter two integer values (a counting or whole number like 1, 216, -35, or 0) Make the following changes/additions to the code: On line 11, change the String myName from “your full name goes here!!!” to your...
Please show screenshot outputs and fully functional code for the Java program. Write the following methods...
Please show screenshot outputs and fully functional code for the Java program. Write the following methods to   1) read the content of an array of 5 doubles public static double[] readingArray() 2) find and print:the smallest element in an array of 5 double public static void smallest(double [] array) 3) find and print:the largest element in an array of 5 doubles pubic static void largest (double [] array) In the main method - invoke readingArray and enter the following numbers...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT