Question

Note: Please write the Pseudocode using Arrays method in Java language. Program 2 (40%); For this assignment, were going to

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

PSEUDO CODE

- If you hold a Cards = 5; then beftialite The Array =5. and Decdare Add elements in Arkay=0. By using or for coop or while >

Checks for a given Condition. If sum is greater then 25. prelut losely, and Stops the program u you losel. and Break. the lo

JAVA PROGRAM

import java.util.*;
import java.util.concurrent.ThreadLocalRandom;

public class game{
public static void main(String[] args){
   //intialzation array//
   int ar[]=new int[5];
   int i=0,j,sum=0,num=0;
  
   while(true){
   //inserting 0 in array//
   for(int p=0;p<5;p++){
   ar[p]=0;  
       }
   i=0;sum=0;num=0;
   //generates random number 1-6;//
   int firstrand=ThreadLocalRandom.current().nextInt(1,6);
   //generates random numbers between 1-9 ans adds random numbers//
   while(i<firstrand){
   ar[i]=ThreadLocalRandom.current().nextInt(2,9+1);          
   sum=sum+ar[i];
   i+=1;
   }  
    for(j=0;j<5;j++){
   System.out.print(ar[j]);      
   System.out.print(" ");
   if(ar[j]!=0){
   num+=1;      
   }
   }
   System.out.println();
   System.out.print("Sum is : ");
   System.out.print(sum);
   System.out.println();
   System.out.print("Num cards : ");
   System.out.print(num);
   System.out.println();
   if(sum>25){
   System.out.print("You lose!");  
   //stop running program//
   break;
       }      
   else if(num==5 && sum <25){
   System.out.print("You Win!");  
   break;
   }
   else if(sum>21 && sum <25){
       System.out.print("You Win!");
       break;
       }
   //continues loop until meets its criteria//  
   else{
   System.out.print("Get another card or 2) Stay: 1");
   System.out.println();
   }
   }
      

   }
}

OUTPUT:

BL Command Prompt C:\Users\kpras\Desktop>java game 6 3 7 92 Sum is : 27 Num cards : 5 You lose! C:\Users\kpras\Desktop>javac

BL Command Prompt C:\Users\kpras\Desktop>java game 6 3 7 92 Sum is : 27 Num cards : 5 You lose! C:\Users\kpras\Desktop>javac game.java C:\Users\kpras\Desktop>java game 7@@@@ Sum is : 7 Num cards : 1 Get another card or 2) Stay: 1 2 8 7 4 5 Sum is : 26 Num cards : 5 You lose! C:\Users\kpras\Desktop>javac game.java C:\Users\kpras\Desktop>Java game 8 9 2 7 @ Sum is : 26 Num cards : 4 You lose! C:\Users\kpras\Desktop>javac game.java C:\Users\kpras\Desktop>java game 28 9 @ @ Sum is : 19 Num cards : 3 Get another card or 2) Stay: 1 8 @ @ @ @ Sum is : 8 Num cards : 1 Get another card or 2) Stay: 1 5 @ @ @ @ Sum is : 5 Num cards : 1 Get another card or 2) Stay: 1 2 3 6 3 Sum is : 14 Num cards : 4 Get another card or 2) Stay: 1 B@@@@ Sum is : 8 Num cards : 1 Get another card or 2) Stay: 1 8 893 @ Sum is : 28 Num cards : 4 You lose! C:\Users\kpras\Desktop> Activate Wind Go to Settings to a

Add a comment
Know the answer?
Add Answer to:
Note: Please write the Pseudocode using Arrays method in Java language. Program 2 (40%); For this...
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
  • "Blackjack 40" my teacher created this assignment and I need help. He is using c++ and...

    "Blackjack 40" my teacher created this assignment and I need help. He is using c++ and has provided this template: Further instructions are below the template! #include <iostream> #include <cmath> #include <cstdlib> using namespace std; //Will return a number from 1 to 13, representing the face of a card int draw_card() { return rand() % 13 + 1; } int main() { const int BET = 10; //This will allow you to control chance, to make testing easier cout <<...

  • 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...

  • 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...

  • 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...

  • plz type it for me 2. Write a program to play a very modified version of...

    plz type it for me 2. Write a program to play a very modified version of spades. The program will select two hands of 5 cards for a single player and the computer dealer. The hands should be chosen using a function and the random methods we discussed in class. Your function should check the cards to be sure that they have not been used in the other hand. If so, then another card will be chosen at random until...

  • This is a must for a C++ project. Blackjack Requested files: Blackjack.cpp (Download) Type of work:...

    This is a must for a C++ project. Blackjack Requested files: Blackjack.cpp (Download) Type of work: Individual work You MUST have grade 70 or higher on the quiz before you can access this assignment. In the card game named 'Blackjack' players get two cards to start with, and then they are asked whether or not they want more cards. Players can continue to take as many cards as they like. Their goal is to get as close as possible to...

  • 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....

  • 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...

  • This is in C++. The program needs to show the points as well. The blue boxes...

    This is in C++. The program needs to show the points as well. The blue boxes show below are the output and it should look like that. Thanks (Game: craps) Craps is a popular dice game played in casinos. Write a program to play a variation of the game, as follows: Roll two dice. Each die has six faces representing values 1, 2, ..., and 6, respectively. Check the sum of the two dice. If the sum is 2, 3,...

  • Write a Java program that reads 5 integers, each of which is in the range of...

    Write a Java program that reads 5 integers, each of which is in the range of 1 and 13 representing a simplified poker card with no suit. Your program should then print the ranking of the hand with card number(s) besides the ranking. The rankings to determine are Four of a Kind(4 of the 5 cards of the same rank), Full House(3 of the 5 cards of the same rank, and 2 cards of another rank), Straight(5 cards of sequential...

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