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 p

ID: 3728260 • Letter: W

Question

Write a program to implement a simple “Hi-Lo” game using a standard deck of 52 playing cards. The game should ask the user to enter their bankroll. Your program must verify that the user enters a positive real number. But, if the user doesn't enter a positive real number I need to continue to prompt them to enter their bankroll until they do. After a valid bankroll has been entered 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, I need to 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:

1. 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 between $0.01 and $100.00.

2. Draw a card and display it for the user.

3. Ask the user if they think the next card will be higher or lower than the card which was drawn.

4. 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 exactly the same (e.g., both are the Ace of Clubs), continue to draw the second card until a different card is drawn.

5. Display the result for the user.

a. If the user guessed correctly add the amount of the bet to their bankroll.

b. If the user guessed incorrectly, subtract the amount of the bet from their bankroll.

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

6. Display the amount in the user’s bankroll after each play of the game before asking whether the user wants to play again.

I also need go incorporate these things into the code:

1. Declare two instances of PlayIngCard objects.  

PlayingCard cardOne = new PlayingCard();

PlayingCard cardTwo = new PlayingCard();

2. Use the isEquals method to ensure the two instances of PlayingCard objects are somehow different so the deck doesn't contain two cards which are exactly alike (e.g. two Queen of Hearts cards). The following code segment accomplishes it.

do

{

cardTwo.drawCard();

} while (cardOne.isEquals(cardTwo));

3. When you are determining whether you won, lost or tied, use the getFace() accessor method to find the card's face value. Then compare them.

This is the template I have to use:

import java.util.Random;


public class PlayingCard
{
   private int face;
   private int suit;

   //-------------------------------------------------------------------
   // Sets up the playing card by drawing it initially.
   //-------------------------------------------------------------------
   public PlayingCard ()
   {
drawCard();
   }

   //-------------------------------------------------------------------
   // Draws the playing card by randomly choosing face and suit values.
   //-------------------------------------------------------------------
   public void drawCard ()
   {
face = (int) (Math.random() * 13) + 2;
suit = (int) (Math.random() * 4);
   }

   //-------------------------------------------------------------------
   // Returns true if the current playing card is exactly the same as
   // the card passed in as a parameter.
   //-------------------------------------------------------------------
   public boolean isEquals (PlayingCard c)
   {
return (face == c.face && suit == c.suit);
   }

   //-------------------------------------------------------------------
   // Returns the face value of the current playing card.
   //-------------------------------------------------------------------
   public int getFace()
   {
return face;
   }

   //-------------------------------------------------------------------
   // Returns the suit value of the current playing card.
   //-------------------------------------------------------------------
   public int getSuit()
   {
return suit;
   }

   //-------------------------------------------------------------------
   // Returns the current playing card as a string.
   //-------------------------------------------------------------------
   public String toString()
   {
String cardName = null;

switch (face)
{
   case 2: cardName = "Two";
   break;
   case 3: cardName = "Three";
   break;
   case 4: cardName = "Four";
   break;
   case 5: cardName = "Five";
   break;
   case 6: cardName = "Six";
   break;
   case 7: cardName = "Seven";
   break;
   case 8: cardName = "Eight";
   break;
   case 9: cardName = "Nine";
   break;
   case 10: cardName = "Ten";
   break;
   case 11: cardName = "Jack";
   break;
   case 12: cardName = "Queen";
   break;
   case 13: cardName = "King";
   break;
   case 14: cardName = "Ace";
}

switch (suit)
{
   case 0: cardName += " of Clubs";
   break;
   case 1: cardName += " of Spades";
   break;
   case 2: cardName += " of Hearts";
   break;
   case 3: cardName += " of Diamonds";
   break;
}

return cardName;
   }
}

Explanation / Answer

CODE

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");

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){

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

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

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

x =input.nextInt();

if(x==1){

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

bet = input.nextInt();

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

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();

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

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

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(guess==1){

if(Random_face1==Random_face){

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

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

ties++;

}

else if(Random_face1>Random_face){

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

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

bankroll+=bet;

wins++;

}

else {

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

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

bankroll-=bet;

loss++;

}

}

else{

if(Random_face1==Random_face){

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

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

ties++;

}

else if(Random_face1<Random_face){

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

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

bankroll+=bet;

wins++;

}

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

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

bankroll-=bet;

loss++;

}

}

played++;

if(bankroll==0){

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

break;

}

  

}

else{

break;

}

}

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);

}

}

If any queries regarding code and execution please get back to me

Thank You

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