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

I need help desinging a java code for the following project. It is an intro code

ID: 3726928 • Letter: I

Question

I need help desinging a java code for the following project. It is an intro code class for java and I'm primarily having trouble designing the random number game method. I've included the instructions as well as an example of the program execution.

A program is needed that will simulate a game of chance, where the player bets on the outcome of a Snail Race. The player will be allowed to repeatedly select one of the following choices from the menu as long as the player does not choose to quit the game or the player has not lost all of his/her money through choosing snails that did not win a race. Choose a snail upon which to place a bet Choose to just watch a race, but not place a bet on a snail Choose to leave the races (quit the game) When the player selects a snail, the game action will proceed as follows: provide the player the ability to enter an amount of money that he/she wants to wager on the snail winning the race simulate the racing of the snails through the use of the random number generator to determine which of the snails wins the race and display which snail won the race determine whether the player’s chosen snail won the race and either add to the player’s money by 2 times the bet if the player’s chosen snail won or subtract from the player’s money the amount of the bet if the player’s chosen snail did not win the race display the player’s current amount of remaining money re-display the game menu to the player and allow the game to begin again with the remaining amount of player’s money Should the player select the option to “Just Watch”, the game action will proceed as follows: simulate the racing of the snails through the use of the random number generator to determine which of the snails wins the race display the player’s current amount of remaining money re-display the game menu to the player and allow the game to begin again with the remaining amount of player’s money Should the player select the option to “Leave the races” or the player has lost all of his money in the game, the game action will proceed as follows: drop out of the game loop following the game loop determine whether the player has any money left and output one of the following messages before ending the program: o if player has no money left – output a message that wishes the player better luck next time and asks him/her to come play again soon o if player has more money left than starting amount – output a message that congratulations the player on the winnings and asks him/her to come play again soon. Page 2 of 5 o if player has some money left – output a message that thanks the player for playing and asks him/her to come play again soon an example of the program output would be: Welcome to the snail races! You have 200.00 dollars. Races Menu 1) Bet on Speedy 2) Bet on Zippy 3) Bet on Slick 4) Just watch, no bet 0) Leave the races Select a snail: 1 Snail Speedy is a good choice! How much would you like to bet on Speedy 50.00 And the snails are off Look at them GO!!! The winner is Slick You lose -50.00 dollars

Explanation / Answer


import java.util.Random;
import java.util.Scanner;

public class SnailRaceSimulator {
public static void main(String[] args) {
  // TODO Auto-generated method stub
  Scanner scan = new Scanner(System.in);
  int userChoice = 9999;
  int moneyLeft = 200;
  int betAmount = 0;
  int snailWon = 9999;
  String outCome;
  String[] snailList = { "","Speedy", "Zippy", "Slick" };
  do {
   if (moneyLeft == 0)
    break;
   System.out.println("Welcome to the snail races! You have " + moneyLeft + " dollars");
   System.out.println("Race Menu");
   System.out.println("1) Bet on Speedy");
   System.out.println("2) Bet on Zippy");
   System.out.println("3) Bet on Slick ");
   System.out.println("4) Just watch, no bet");
   System.out.println("0) Leave the races");
   System.out.print("Select Snail: ");
   userChoice = scan.nextInt();
   if (userChoice == 1) {
    System.out.print("Snail Speedy is a good choice!How much would you like to bet on Speedy: ");
    betAmount = scan.nextInt();
    System.out.println("The snails are off Look at them GO!!!");
    snailWon = getRandomNumber();
    if (userChoice == snailWon) {
     System.out.println("The winner is " + snailList[snailWon] + "You Win "+ betAmount+" dollars");
     moneyLeft += betAmount;
    } else {
     System.out.println("The winner is " + snailList[snailWon] + "You loss -"+betAmount+" dollars");
     moneyLeft -= betAmount;
    }
   } else if (userChoice == 2) {
    System.out.print("Snail Zippy is a good choice!How much would you like to bet on Zippy: ");
    betAmount = scan.nextInt();
    System.out.println("The snails are off Look at them GO!!!");
    snailWon = getRandomNumber();
    if (userChoice == snailWon) {
     System.out.println("The winner is " + snailList[snailWon] + "You Win "+ betAmount+" dollars");
     moneyLeft += betAmount;
    } else {
     System.out.println("The winner is " + snailList[snailWon] + "You loss -"+betAmount+" dollars");
     moneyLeft -= betAmount;
    }
   } else if (userChoice == 3) {
    System.out.print("Snail Slick is a good choice!How much would you like to bet on Slick: ");
    betAmount = scan.nextInt();
    System.out.println("The snails are off Look at them GO!!!");
    snailWon = getRandomNumber();
    if (userChoice == snailWon) {
     System.out.println("The winner is " + snailList[snailWon] + "You Win "+ betAmount+" dollars");
     moneyLeft += betAmount;
    } else {
     System.out.println("The winner is " + snailList[snailWon] + "You loss -"+betAmount+" dollars");
     moneyLeft -= betAmount;
    }
   } else if (userChoice == 0) {
    break;
   } else if(userChoice==4) {
    snailWon = getRandomNumber();
    System.out.println("The winner is " + snailList[snailWon]);
   }else
   {
    System.out.println("Wrong choice!!");
    continue;
   }
  } while (true);
  if (moneyLeft > 0)
   System.out.println("Thank You for playing the game!! You have won " + moneyLeft);
  else
   System.out.println("Thank You for playing the game!! Better lunk next time ");
}

public static int getRandomNumber() {
  Random rand = new Random();
  int x = rand.nextInt(4);
  while(x==0)
   x = rand.nextInt(4);
  return x;
}
}

=========================OUTPUT====================

Welcome to the snail races! You have 200 dollars
Race Menu
1) Bet on Speedy
2) Bet on Zippy
3) Bet on Slick
4) Just watch, no bet
0) Leave the races
Select Snail: 4
The winner is Slick
Welcome to the snail races! You have 200 dollars
Race Menu
1) Bet on Speedy
2) Bet on Zippy
3) Bet on Slick
4) Just watch, no bet
0) Leave the races
Select Snail: 1
Snail Speedy is a good choice!How much would you like to bet on Speedy: 30
The snails are off Look at them GO!!!
The winner is SpeedyYou Win 30 dollars
Welcome to the snail races! You have 230 dollars
Race Menu
1) Bet on Speedy
2) Bet on Zippy
3) Bet on Slick
4) Just watch, no bet
0) Leave the races
Select Snail: 3
Snail Slick is a good choice!How much would you like to bet on Slick: 70
The snails are off Look at them GO!!!
The winner is SpeedyYou loss -70 dollars
Welcome to the snail races! You have 160 dollars
Race Menu
1) Bet on Speedy
2) Bet on Zippy
3) Bet on Slick
4) Just watch, no bet
0) Leave the races
Select Snail: 4
The winner is Slick
Welcome to the snail races! You have 160 dollars
Race Menu
1) Bet on Speedy
2) Bet on Zippy
3) Bet on Slick
4) Just watch, no bet
0) Leave the races
Select Snail: 1
Snail Speedy is a good choice!How much would you like to bet on Speedy: 50
The snails are off Look at them GO!!!
The winner is SpeedyYou Win 50 dollars
Welcome to the snail races! You have 210 dollars
Race Menu
1) Bet on Speedy
2) Bet on Zippy
3) Bet on Slick
4) Just watch, no bet
0) Leave the races
Select Snail: 0
Thank You for playing the game!! You have won 210

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