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

Java Programming Build A Game Program This Game is called Price-is-Right Wheel S

ID: 3711188 • Letter: J

Question

Java Programming

Build A Game Program

This Game is called Price-is-Right Wheel Spin.

I. Write a program to implement the Wheel Spin on “The Price is Right”.

II. The Wheel Spin Game has 3 players. The Wheel has the numbers 5, 10, 15, 20 …100. 20 Numbers. Use Random Numbers to generate these numbers. The rules are that each Player gets at most 2 spins but they cannot go over 100. If the Player goes over 100 they are out. The player can decide if he/she wants a second spin or not, after they see the result of the first spin. At the end the player with the highest value, without going over 100, wins.

III. If a player hits exactly 100, they can win more money. The player that hits 100 exactly gets one additional spin after all 3 Players have finished spinning. If they hit 100 again, they get $25,000. If they hit 5 or 15, they get $15,000.

IV. Once the User of this game plays the game once, ask the User if they want to play again.

V. Build the code to play this game. Do not put all your code in main(). Use Functions where appropriate. Use Scanner to read in User input for decisions and whether the User wants to play again.

Explanation / Answer

CODE: PRICEISRIGHTWHEELSPIN.JAVA

import java.io.*;
import java.util.*;
import java.lang.*;
import java.util.Random;

class Player
{
   public String name;
   public int points;
   public int totalspins;
   public boolean playerisout;
   public int prizemoney;
   public boolean isawinner;

   public Player(String n) {

       name = n;
       Init();
  
   }

   public void Init()   {
        points = 0;
       totalspins =0;
       playerisout = false;
       prizemoney = 0;
       isawinner = false;
   }

}

public class PriceIsRightWheelSpin
{
   public static int Spin(Player currentplayer)
   {
       int points = 0;

       if (currentplayer.playerisout == false )
       {
           Random rand = new Random();
          
           int n = rand.nextInt(20) + 1;
           currentplayer.totalspins = currentplayer.totalspins +1;

           if (currentplayer.totalspins == 2 && currentplayer.points==100)
           {
               //this is a second spin which is not allowed as points=100
               System.out.printf(" PLAYER %s : SPIN NOT ALLOWED AS POINTS EQUALS 100 (Total Spins=%d): TOTAL POINTS =%d", currentplayer.name,currentplayer.totalspins,currentplayer.points);
           }

          

           points = n*5;
          
           //add points only for first two spins
           if (currentplayer.totalspins <=2 && currentplayer.points<100)
           {
               currentplayer.points = currentplayer.points + points;
           }
          
          
           if (currentplayer.points > 100 && currentplayer.totalspins <=2)
           {
               currentplayer.playerisout = true;
           }

           System.out.printf(" PLAYER %s : SPIN NUMBER %d : TOTAL POINTS SO FAR=%d", currentplayer.name,currentplayer.totalspins,currentplayer.points);
          
           //add prizemoney for bonus spin
           if (currentplayer.totalspins == 3)
           {
          
               if (points==100)
               {
                   currentplayer.prizemoney = currentplayer.prizemoney + 25000;
                   congragulate(currentplayer);
               }
               else if (points==5 || points==15)
               {
                   currentplayer.prizemoney = currentplayer.prizemoney + 15000;
                   congragulate(currentplayer);
               }
               else
               {
                   System.out.printf(" PLAYER %s : YOU DID NOT WIN A JACKPOT. SPINNING NUMBER WAS %d", currentplayer.name,points);
               }
           }

       }
       else
       {
           System.out.printf(" PLAYER %s : SPIN NOT ALLOWED AS POINTS ABOVE 100 (Total Spins=%d): TOTAL POINTS =%d", currentplayer.name,currentplayer.totalspins,currentplayer.points);
       }
      
       return points; //returns the number fetched on the spin

   }

   public static boolean AskPlayerIfWannaSpin(Player p)
   {

           boolean DidPlayerSpin = false;

           System.out.printf("            PLAYER %s. DO YOU WANT TO SPIN(type y or Y for yes)", p.name);
           Scanner scanner = new Scanner(System.in);
           if (scanner.next().equalsIgnoreCase("y"))
           {
               Spin(p);
               DidPlayerSpin = true;
           }
          
           return DidPlayerSpin;
   }

   public static void AnnounceWinner(Player[] players)
   {
       int totalplayers = players.length;
       int winnerplayernumber = -1;
       int maxbelow100 = 0;
       int points;
       boolean wasThereAnyWinner = false;
      

       for (int i=0;i<totalplayers;i++)
       {
           points = players[i].points;
           if (points <=100 && points >=maxbelow100)
           {
               players[i].isawinner = true;
              
               if (points <= 100 && i > 0)
               {
                   if (players[i-1].points != 100)
                       players[i-1].isawinner = false; //last set winner is no longer a winner
               }

               maxbelow100 = points;
               wasThereAnyWinner = true;
           }
           else
           {
               players[i].isawinner = false;
           }
       }

       if (wasThereAnyWinner == true)
       {
           for (int i=0;i<totalplayers;i++)
           {
               if (players[i].isawinner == true)
               {
                   System.out.printf(" Player %s is a winner with total points %d and jackpot prize money $%d", players[i].name, players[i].points,players[i].prizemoney);
               }
           }
       }
       else
           System.out.printf("               THERE WERE NO WINNERS AS EVERYONE SCORED ABOVE 100");

   }

   public static void PressAnyKeyToContinue()
   {
           System.out.printf(" Press any key to continue");
           Scanner scanner = new Scanner(System.in);
           scanner.nextLine();
   }

   public static void congragulate(Player currentplayer)
   {
       System.out.printf(" CONGRAGULATION PLAYER %s. YOU WON THE JACKPOT PRIZE OF $%d",currentplayer.name ,currentplayer.prizemoney );
   }

   public static void main(String args[])
   {
       int totalplayers = 3;

       //create three players
       Player[] players = new Player[totalplayers];
      

       for (int i=0;i<totalplayers;i++)
       {
           players[i] = new Player(Integer.toString(i+1));
       }
      
       //PLAY MUST GO ON
       while(true)
       {
           //make sure player is reinitialized before new game
           for (int i=0;i<totalplayers;i++)
           {
               players[i].Init();
           }
          
           //first spin
           System.out.printf(" -----------------------------------------------------------");
           System.out.printf(" -----------------------------------------------------------");
           System.out.printf(" -----------------------------------------------------------");
           System.out.printf("             W E L C O M E    T O    T H E ");
           System.out.printf("             PRICE-IS-RIGHT WHEEL SPIN GAME");
           System.out.printf(" -----------------------------------------------------------");
           System.out.printf(" -----------------------------------------------------------");
           System.out.printf(" -----------------------------------------------------------");

          
           //first spin
           System.out.printf("           HERE STARTS THE FIRST SPIN FOR ALL PLAYERS ");
           System.out.printf(" ------------------------------------------------------ ");
          
           PressAnyKeyToContinue();

           for (int i=0;i<totalplayers;i++)
           {
               Spin(players[i]);
           }

           PressAnyKeyToContinue();

          
           //second spin
           System.out.printf("            HERE STARTS THE SECOND SPIN FOR ALL PLAYERS");
           System.out.printf(" ------------------------------------------------------ ");
           for (int i=0;i<totalplayers;i++)
           {
               //ask player if they wish to spin
               AskPlayerIfWannaSpin(players[i]);
           }

          
           PressAnyKeyToContinue();

           System.out.printf("            NOW PLAYERS WITH 100 POINTS GET ADDITIONAL SPIN FOR JACKPOT");
           System.out.printf(" -----------------------------------------------------------------------");
          
           boolean AnyPlayerEligibleForJackpotSpin = false;
          
           for (int i=0;i<totalplayers;i++)
           {  
               if (players[i].points == 100)
               {
                   AnyPlayerEligibleForJackpotSpin = true;

                   //ask player if they wish to spin
                   AskPlayerIfWannaSpin(players[i]);
               }

           }

           if (AnyPlayerEligibleForJackpotSpin == false)
               System.out.printf(" There was no player eligible for jackpot ");

           PressAnyKeyToContinue();

           System.out.printf("                       W I N N E R");
           System.out.printf(" --------------------------------------------------------- ");
          

           AnnounceWinner(players);

          
           System.out.printf("               DO YOU WISH TO PLAY AGAIN (type y or Y for yes)?");
           Scanner scanner = new Scanner(System.in);
           if (!scanner.next().equalsIgnoreCase("y"))
           {
               break;
           }

       } //end while

   System.out.printf(" --------------------------------------------------------------------------- ");
   System.out.printf("                         THANK YOU. UNTIL NEXT TIME. SAYONAARA !!!!");
   System.out.printf(" --------------------------------------------------------------------------- ");

   }//end main
}// end main class

OUTPUT


D:Program FilesJavajdk1.8.0_91in>javac PriceIsRightWheelSpin.java

D:Program FilesJavajdk1.8.0_91in>java PriceIsRightWheelSpin


-----------------------------------------------------------
-----------------------------------------------------------
-----------------------------------------------------------
            W E L C O M E    T O    T H E
            PRICE-IS-RIGHT WHEEL SPIN GAME
-----------------------------------------------------------
-----------------------------------------------------------
-----------------------------------------------------------

          HERE STARTS THE FIRST SPIN FOR ALL PLAYERS

------------------------------------------------------

Press any key to continue

PLAYER 1 : SPIN NUMBER 1 : TOTAL POINTS SO FAR=45
PLAYER 2 : SPIN NUMBER 1 : TOTAL POINTS SO FAR=40
PLAYER 3 : SPIN NUMBER 1 : TOTAL POINTS SO FAR=85

Press any key to continue


           HERE STARTS THE SECOND SPIN FOR ALL PLAYERS

------------------------------------------------------


           PLAYER 1. DO YOU WANT TO SPIN(type y or Y for yes)y

PLAYER 1 : SPIN NUMBER 2 : TOTAL POINTS SO FAR=100


           PLAYER 2. DO YOU WANT TO SPIN(type y or Y for yes)y

PLAYER 2 : SPIN NUMBER 2 : TOTAL POINTS SO FAR=120


           PLAYER 3. DO YOU WANT TO SPIN(type y or Y for yes)y

PLAYER 3 : SPIN NUMBER 2 : TOTAL POINTS SO FAR=90

Press any key to continue


           NOW PLAYERS WITH 100 POINTS GET ADDITIONAL SPIN FOR JACKPOT

-----------------------------------------------------------------------


           PLAYER 1. DO YOU WANT TO SPIN(type y or Y for yes)y

PLAYER 1 : SPIN NUMBER 3 : TOTAL POINTS SO FAR=100
PLAYER 1 : YOU DID NOT WIN A JACKPOT. SPINNING NUMBER WAS 50

Press any key to continue


                      W I N N E R

---------------------------------------------------------


Player 1 is a winner with total points 100 and jackpot prize money $0


              DO YOU WISH TO PLAY AGAIN (type y or Y for yes)?y


-----------------------------------------------------------
-----------------------------------------------------------
-----------------------------------------------------------
            W E L C O M E    T O    T H E
            PRICE-IS-RIGHT WHEEL SPIN GAME
-----------------------------------------------------------
-----------------------------------------------------------
-----------------------------------------------------------

          HERE STARTS THE FIRST SPIN FOR ALL PLAYERS

------------------------------------------------------

Press any key to continue

PLAYER 1 : SPIN NUMBER 1 : TOTAL POINTS SO FAR=95
PLAYER 2 : SPIN NUMBER 1 : TOTAL POINTS SO FAR=35
PLAYER 3 : SPIN NUMBER 1 : TOTAL POINTS SO FAR=40

Press any key to continue


           HERE STARTS THE SECOND SPIN FOR ALL PLAYERS

------------------------------------------------------


           PLAYER 1. DO YOU WANT TO SPIN(type y or Y for yes)n

           PLAYER 2. DO YOU WANT TO SPIN(type y or Y for yes)y

PLAYER 2 : SPIN NUMBER 2 : TOTAL POINTS SO FAR=80


           PLAYER 3. DO YOU WANT TO SPIN(type y or Y for yes)y

PLAYER 3 : SPIN NUMBER 2 : TOTAL POINTS SO FAR=75

Press any key to continue


           NOW PLAYERS WITH 100 POINTS GET ADDITIONAL SPIN FOR JACKPOT

-----------------------------------------------------------------------


There was no player eligible for jackpot


Press any key to continue


                      W I N N E R

---------------------------------------------------------


Player 1 is a winner with total points 95 and jackpot prize money $0


              DO YOU WISH TO PLAY AGAIN (type y or Y for yes)?n


---------------------------------------------------------------------------

                         THANK YOU. UNTIL NEXT TIME. SAYONAARA !!!!

---------------------------------------------------------------------------


D:Program FilesJavajdk1.8.0_91in>

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