Exercise 8 -HiLo a) In the Hi-Lo game, the player begins with a score of 1000. The player is prompted for the number of points to risk and a second prompt asks the player to choose either High or Low. The player's choice of either High or Low is compared to random number between 1 and 13, inclusive. If the number is between 1 and 6 inclusive, then it is considered "low". A number between 8 and 13 inclusive is “high". The number 7 is neither high nor low, and the player loses the points at risk. If the player had guessed correctly, the points at risk are doubled and added to the total points. For a wrong choice, the player loses the points at risk. Create a HiLo application based on this specification. Application output should look similar to: High Low Game RULES Numbers 1 through 6 are low Numbers 8 through 13 are high Number ? is neither high or low You have 1000 po ints. Enter points to risk: 500 Predict (1=High, 0=Low>: 0 Number is 4 You win. Play again? y You have 2000 points. b) Modify the application to allow the player to continue until there are 0 points left. At the end of the game, display the number of guesses the user took before running out of points.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I did part A but I really need all parts of part B answered I want the code to continue after 0 with negative numbers and I need the guesses to show up at the end that shows how many guesses it took before the user ran out of points.

import java. util.Random;

import java.util. Scanner;

import java.util.regex.*;

public class HiLOGame{

public static void main( String(] args){

final int MAX POINT = 1000-

int point = MAX POINT:

int numberOfGuess = 0;

do {

numberOfGuess++:

showStatus(point);

int point ToRisk = getPointToRisk("Enter point to risk? ", point);

String option = getHiLoOption ("Enter either Hi or Lo?");

int magicNumber = getMagicNumber(1, 13);

/I for debug

//System.out.printf(String.format ("Magic number: %d%n",. magicNumber));

if (isWon(option, magicNumber)) {

point += pointToRisk:

System.out.printin("You Won this game.");

} else f

point -= pointToRisk:

System.out.printin("You Lost this game.");


 

}


 

}while (point > 0):

report(MAX POINT, numberOfGuess);

System.exit(0);

}


 

private static void report(int point, int numberOfGuess) {

String message = "It took % number(s) of guess before running out of %,d points. %n"

System.out.printf(message, numberOfGuess, point);


 

}


 

private static void showStatus(int point) {

String message = "You have % number of points to risk. %n",

System.out.printf(message, point);


 

}



 

public static int getMagicNumber(int min, int max) {

int result = 1:

Random rnd = new Random():

result=Math.abs(rnd.nextint() % (max - min)) + 1

return result;


 

}


 

private static int getPointToRisk(String message, int point) {

System.out. print(message);

Scanner keyboard = new Scanner(System.in);

int result = keyboard. nextInt@);

if (result > point) {

result = point;

}

return result;

}

public static String getHiLoOption(String message) {

String result = "hi".

boolean done = false;


 

do{


 

System.out. printin(message);

Scanner keyboard = new Scanner(System.in);

String option= keyboard.next0.

if (isValid(option)) {

result = option;

done = true:


 

} else {

System.out.printf("Invalid option I'"%s'" was entered, valid options are either Hi or Lo. Try again. %n" option);

}

} while (!done);

return result;

private static boolean isValid(String option) {

boolean result = false;

Pattern p = Pattern.compile("(hi)lo)", Pattern. CASE _INSENSITIVE);

Matcher m = p.matcher(option);

result = m.findo:

return result;

}

private static boolean isWon(String option, int guessNumber) f

boolean result = false:

if (option.equalsignoreCase("hi"') && (guessNumber >= 8)) f

result = true:

} else if (option. equalsignoreCase("lo") && (quessNumber <= 6)) f

result = true;

}

return result;

}

}

Exercise 8
HiLo
a) In the Hi-Lo game, the player begins with a score of 1000. The player is prompted for the
number of points to risk and a second prompt asks the player to choose either High or
Low. The player's choice of either High or Low is compared to random number between
1 and 13, inclusive. If the number is between 1 and 6 inclusive, then it is considered
"low". A number between 8 and 13 inclusive is “high". The number 7 is neither high
nor low, and the player loses the points at risk. If the player had guessed correctly,
the points at risk are doubled and added to the total points. For a wrong choice, the
player loses the points at risk. Create a HiLo application based on this specification.
Application output should look similar to:
High Low Game
RULES
Numbers 1 through 6 are low
Numbers 8 through 13 are high
Number 7 is neither high or low
You have 1000 points.
Enter points to risk: 500
Predict (1=High, 0=Low): 0
Number is 4
You win.
Play again? y
You have 2000 points.
b) Modify the application to allow the player to continue until there are 0 points left. At
the end of the game, display the number of guesses the user took before running out
of points.
Transcribed Image Text:Exercise 8 HiLo a) In the Hi-Lo game, the player begins with a score of 1000. The player is prompted for the number of points to risk and a second prompt asks the player to choose either High or Low. The player's choice of either High or Low is compared to random number between 1 and 13, inclusive. If the number is between 1 and 6 inclusive, then it is considered "low". A number between 8 and 13 inclusive is “high". The number 7 is neither high nor low, and the player loses the points at risk. If the player had guessed correctly, the points at risk are doubled and added to the total points. For a wrong choice, the player loses the points at risk. Create a HiLo application based on this specification. Application output should look similar to: High Low Game RULES Numbers 1 through 6 are low Numbers 8 through 13 are high Number 7 is neither high or low You have 1000 points. Enter points to risk: 500 Predict (1=High, 0=Low): 0 Number is 4 You win. Play again? y You have 2000 points. b) Modify the application to allow the player to continue until there are 0 points left. At the end of the game, display the number of guesses the user took before running out of points.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Returning value from Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education