Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program to implement a simple \"Hi-Lo\" game using a standard deck of 52

ID: 3539730 • Letter: W

Question

Write a program to implement a simple "Hi-Lo" game using a standard deck of 52 playing cards. Your game should ask the user to enter their bankroll. Your program must verify that the user enters a positive real number. If the user did not enter a positive real number, continue to prompt them to enter their bankroll until they do so. The program should continue to repeat until either the user indicates that they want to quit or until there is no money remaining in their bankroll. When the game ends, display for the user the total number of games played, total number of wins, total number of losses, total number of ties and the ending amount in their bankroll.

For each play of the game, ask the user to enter their bet. Verify that the user has sufficient funds remaining in their bankroll to cover the bet and that the bet is less than $100.00. Draw a card and display it for the user. Ask the user if they think the next card will be higher or lower than the card which was drawn. Draw a second card making sure that it is different in some way (either face, suit or both) from the first card drawn. If the card is the same, continue to draw the second card until a different card is drawn. If the user guessed correctly add the amount of the bet to their bankroll. If the user guessed incorrectly, subtract the amount of the bet from their bankroll. If the second card drawn is a card of the same face value but a different suit, the game is a tie and no change should be made to the user's bankroll. Display the amount in the user's bankroll after each play of the game before asking whether the user wants to play again.

Explanation / Answer

import java.util.*;

public class game {


public static void main(String[] args){

int bankroll;

Scanner input = new Scanner(System.in);

System.out.println("Enter Your Bankroll must be +ve");

bankroll = input.nextInt();

System.out.println("Game");

//Definition of Cards //

System.out.println("Suits");

System.out.println("");

System.out.println("1 : Club");

System.out.println("2 : Diamond");

System.out.println("3 : Hearts");

System.out.println("4 : Spade");

System.out.println("");

System.out.println("");

System.out.println("Face Value");

System.out.println("");

System.out.println("1 : Ace");

System.out.println("2 : Two");

System.out.println("3 : Three");

System.out.println("4 : Four");

System.out.println("5 : Five");

System.out.println("6 : Six");

System.out.println("7 : Seven");

System.out.println("8 : Eight");

System.out.println("9 : Nine");

System.out.println("10 : Ten");

System.out.println("11 : Jack");

System.out.println("12 : Queen");

System.out.println("13 : King");

System.out.println("");

System.out.println("");

System.out.println("Cards Example : Card (1,1) is of suit Club and Face value Ace" );

System.out.println("");

int bet,wins=0,loss=0,ties=0,played=0;

int x,guess;

while(bankroll>0)

//Game will go on till user has balance in his account//

{

System.out.println("1 : Play Game ");

System.out.println("2 : Quit ");

System.out.println("Enter Your Choice");

x =input.nextInt();

//User choses to play game//

if(x==1){

System.out.println("Enter Your bet , less than $100");

bet = input.nextInt();

/*Draws random card */

//Draws random suit, either 1,2,3 0r 4//

int Random_suit =1 + (int)(Math.random()*(4));

//Draws random face, from 1,2,3,.... to 13//

int Random_face =1 + (int)(Math.random()*(13));

System.out.println("Card Drawn is "+"("+Random_suit+","+Random_face+")");

System.out.println("Enter Your Guess 1 for high face blue and 2 for low");

guess =input.nextInt();

/*Draws Another random card after user has guessed

whether face value of next drawn card is high or low*/

int Random_suit1 =1 + (int)(Math.random()*(4));

int Random_face1 =1 + (int)(Math.random()*(13));

//If second drawn card is same as first card , then next card is drawn //

if(Random_suit1 == Random_suit)

{

if(Random_face1==Random_face)

{

Random_suit1 =1 + (int)(Math.random()*(4));

Random_face1 =1 + (int)(Math.random()*(13));

}

}

// If user guessed that face value of second drawn card is high than first card //

if(guess==1){

//Both card have same face value//

if(Random_face1==Random_face){

System.out.println(" Next Card Drawn is "+"("+Random_suit1+","+Random_face1+")");

System.out.println("Game Tied");

ties++; // No. of ties increased by one //

}

//Correct Guess: Face value of second card > face value of first card //

else if(Random_face1>Random_face){

System.out.println(" Next Card Drawn is "+"("+Random_suit1+","+Random_face1+")");

System.out.println("You won");

bankroll+=bet; // Account balance is increased//

wins++; //No of wins is increased by one//

}

//Incorrect Guess : Face value of second card < face value of first card //

else {

System.out.println(" Next Card Drawn is "+"("+Random_suit1+","+Random_face1+")");

System.out.println("You Loss");

bankroll-=bet; // Account balance is decreased//

loss++; //No of losses is increased by one//

}

}

// If user guessed that face value of second drawn card is low than first card //

else{

if(Random_face1==Random_face){

//Both card have same face value//

System.out.println(" Next Card Drawn is "+"("+Random_suit1+","+Random_face1+")");

System.out.println("Game Tied");

ties++;

}

//Correct Guess : Face value of second card < face value of first card //

else if(Random_face1<Random_face){

System.out.println(" Next Card Drawn is "+"("+Random_suit1+","+Random_face1+")");

System.out.println("You Won");

bankroll+=bet;// Account balance is increased//

wins++; //No of wins is increased by one//

}

//Incorrect guess : Face value of second card > face value of first card //

else {System.out.println(" Next Card Drawn is "+"("+Random_suit1+","+Random_face1+")");

System.out.println("You Loss");

bankroll-=bet;

// Account balance is decreased//

//No of losses is increased by one//

loss++;

}

}

played++;

if(bankroll==0){

System.out.println("You don't have enough money to play Game:");

break;

}

  

}

else{

break;

}

}

//Displays the entire info of the game//

System.out.println("Games Played : "+played);

System.out.println("Games Win : "+wins);

System.out.println("Games Loss : "+loss);

System.out.println("Games Tied : "+ties);

System.out.println("Amount Left : "+bankroll);

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote