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

In this program use the following methods to make a simple java game and include

ID: 3544758 • Letter: I

Question

In this program use the following methods to make a simple java game and include comments for any block of code:


public static void main(String [] args) //mangaes the main flow of the game and loops until user quits


public static int spinTheWheel() //to return a random number range of 1-10


public static int checkHigher(int spin1, int spin2)

//compares the 1st and 2nd spin

//if spin2 > spin1 return scoreValue 10

//if spin2 < spin1 return scoreValue -10

//if spin1 = spin2 return scoreValue 0


publis static int checkLower(int spin1, int spin2)

//compares the 1st and 2nd spin

//if spin2 > spin1 return scoreValue 10

//if spin2 < spin1 return scoreValue -10

//if spin1 = spin2 return scoreValue 0


Have the user start out with $100 and spin for their 1st 10 digit num of a value 1-10. Have the user guess if the next number to be spinned is either higher or lower than the previous number. If lower the user loses $10, and if they win they gain $10, if they guess the exact number, they keep the current total they have. Continue the game until the user chooses to quit.

Example:

Welcome to the Spin Game

The spinner has only 10 numbers from 1-10

You currently have $100, press ENTER for the 1st spin

You got 4

Spin again. Will your next spin be (H)igher or (L)ower then the previous spin, or (Q)uit? L

You got 2

You won $10, and a total of $110.

Spin again. Will your next spin be (H)igher or (L)ower then the previous spin, or (Q)uit? H

You got 2

You keep you current total of $110

Spin again. Will your next spin be (H)igher or (L)ower then the previous spin, or (Q)uit? L

You got 9

You lose $10, and a total of $100

Spin again. Will your next spin be (H)igher or (L)ower then the previous spin, or (Q)uit? Q


Thank you for playing, your total winnings is $100. Congradulations


Explanation / Answer

import java.util.Scanner;

import java.util.Random;


public class SpinGame {

public static void main (String[] args) {

int cash = 100;

char c;


Scanner numGuess = new Scanner(System.in);

System.out.println("The High-Low Spinner Game. The spinner has 10 numbers from 1-10. You currently have $100 to start with.");

System.out.println("Press enter for ur first Spin"); //desinging the opening Screen

Random r1 = new Random();

int rand1 = r1.nextInt(10) + 1; //getting a random num for First spin and adding 1 to remove '0' from list

System.out.println("First spin = "+rand1); //FIrst spin number

System.out.println();

System.out.println("Do u wanna play?"); //Asking if u wanna play. Answer with y or n.

char decision = numGuess.next().charAt(0); //taking decision from u

while(decision != 'n')

{

int rand2 = r1.nextInt(10) + 1; //taking a random number to check with previous spin

System.out.println("Select H for High and L for Low"); //Select ur option High or Low with 'H' or 'L'

c = numGuess.next().charAt(0);

System.out.println("You spun "+rand2); //Printing the present spin num

if(cash!=0){ //if u have no cash then u leave the game

switch (c) {

case 'H': // if u select High 'H'

case 'h':

if (rand2 > rand1) //if u win

{

System.out.println("You just won the game!");

cash = cash + 10; //add ur winning money

System.out.println("you have $"+cash+" now");

}

else if(rand2 == rand1) //if it's the same num

{

System.out.println("It's the same num..");

System.out.println("you have $"+cash+" now");

}

else{ //if u lose

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

cash = cash - 10; //losing $10 for wrong bet

System.out.println("you have $"+cash+" now");

}

break;

case 'L':

case 'l': if (rand2 < rand1) //if u win

{

System.out.println("You just won the game!");

cash = cash + 10; //add ur winning money

System.out.println("you have $"+cash+" now");

}else if(rand2 == rand1)

{

System.out.println("It's the same num..");

System.out.println("you have $"+cash+" now");

}

else //if u lose

{

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

cash = cash - 10; //losing $10 for wrong bet

System.out.println("you have $"+cash+" now");

}

break;

default:

break;

}

}

rand2=rand1; //saving present spin num to reaccess random num

System.out.println("Do u wanna play more. Press y to continue or n to quit"); //wanna play more

decision = numGuess.next().charAt(0); //yes or no... with 'y' or 'n'

}

System.out.println("Congrats... ur total earnings is $"+cash+" with you"); //Final amount of cash u gonna take home

}}


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