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 and my code is messed up.   import java.util.*; public class HiLo {     public static void main(String[] args) {         final int MAX_POINT = 1000;         int point = MAX_POINT;         int min = 1;         int max = 13;         int guess = 0;         System.out.println("High Low Game.");         System.out.println("RULES.");         System.out.println("1. Numbers 1 through 6 are low .");         System.out.println("2. Numbers 8 through 13 are High .");         System.out.println("3. Numbers 7 is neither high or Low.");         do {             displayPoints(point);             int pointToRisk = enterPointsToRisk(point);             String option = predictHiLo("\nPredict <1=High, 0=Low>: ");             int computerRandomNum = randomNumgen(min, max);             if (resultPoints(option, computerRandomNum)) {                 point += pointToRisk;                 guess += 1;                 System.out.println("You Win.");             } else {                 point -= pointToRisk;                 guess += 1;                 System.out.println("You Lost.");             }             if(point == 0)  {                 System.out.println("It took "  + guess+" guesses to run out of points.");                 break;             }             System.out.print("Play agin? ");             Scanner in = new Scanner(System.in);             char repeat =in.next().charAt(0);             if (repeat == 'Y' || repeat == 'y') {                 continue;             }             else             {                 System.out.println("It took "  + guess+" guesses.");                 System.out.println("See You Later!");                 break;             }         } while (point != 0);     }          public static void displayPoints(int point) {         System.out.println("\nYou have " + point +" points.");     }          public static int randomNumgen(int min, int max) {         int result = 1;         Random rnd = new Random();         result = rnd.nextInt(13 - 1 + 1) + 1;         System.out.println("Number is " +result);         return result;     }     public static int enterPointsToRisk(int point) {         System.out.print("\nEnter Points to risk: ");         Scanner in = new Scanner(System.in);         int inputPoints = in.nextInt();         if (inputPoints > point) {             inputPoints = point;         }         return inputPoints;     }          public static String predictHiLo(String i) {         String option = "";         do {             System.out.print(i);             Scanner in = new Scanner(System.in);             option = in.next();         } while (!(option.equals("1") || option.equals("0")));         return option;     }          public static boolean resultPoints(String option, int guessNumber) {         boolean result = false;         if (option.equals("1") && ((guessNumber >= 8) && (guessNumber <= 13))) {             result = true;             return result;         } else if (option.equalsIgnoreCase("0") && ((guessNumber <= 6) && (guessNumber >= 1))) {             result = true;             return result;         }         else {             return result;         }     } }

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 and my code is messed up.

 

import java.util.*;
public class HiLo {
    public static void main(String[] args) {
        final int MAX_POINT = 1000;
        int point = MAX_POINT;
        int min = 1;
        int max = 13;
        int guess = 0;
        System.out.println("High Low Game.");
        System.out.println("RULES.");
        System.out.println("1. Numbers 1 through 6 are low .");
        System.out.println("2. Numbers 8 through 13 are High .");
        System.out.println("3. Numbers 7 is neither high or Low.");
        do {
            displayPoints(point);
            int pointToRisk = enterPointsToRisk(point);
            String option = predictHiLo("\nPredict <1=High, 0=Low>: ");
            int computerRandomNum = randomNumgen(min, max);
            if (resultPoints(option, computerRandomNum)) {
                point += pointToRisk;
                guess += 1;
                System.out.println("You Win.");
            } else {
                point -= pointToRisk;
                guess += 1;
                System.out.println("You Lost.");
            }
            if(point == 0)  {
                System.out.println("It took "  + guess+" guesses to run out of points.");
                break;
            }
            System.out.print("Play agin? ");
            Scanner in = new Scanner(System.in);
            char repeat =in.next().charAt(0);
            if (repeat == 'Y' || repeat == 'y') {
                continue;
            }
            else
            {
                System.out.println("It took "  + guess+" guesses.");
                System.out.println("See You Later!");
                break;
            }
        } while (point != 0);
    }
    
    public static void displayPoints(int point) {
        System.out.println("\nYou have " + point +" points.");
    }
    
    public static int randomNumgen(int min, int max) {
        int result = 1;
        Random rnd = new Random();
        result = rnd.nextInt(13 - 1 + 1) + 1;
        System.out.println("Number is " +result);
        return result;
    }
    public static int enterPointsToRisk(int point) {
        System.out.print("\nEnter Points to risk: ");
        Scanner in = new Scanner(System.in);
        int inputPoints = in.nextInt();
        if (inputPoints > point) {
            inputPoints = point;
        }
        return inputPoints;
    }
    
    public static String predictHiLo(String i) {
        String option = "";
        do {
            System.out.print(i);
            Scanner in = new Scanner(System.in);
            option = in.next();
        } while (!(option.equals("1") || option.equals("0")));
        return option;
    }
    
    public static boolean resultPoints(String option, int guessNumber) {
        boolean result = false;
        if (option.equals("1") && ((guessNumber >= 8) && (guessNumber <= 13))) {
            result = true;
            return result;
        } else if (option.equalsIgnoreCase("0") && ((guessNumber <= 6) && (guessNumber >= 1))) {
            result = true;
            return result;
        }
        else {
            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
Step 1

Modified code:

import java.util.*;
public class HiLo {
    public static void main(String[] args) {
        final int MAX_POINT = 1000;
        int point = MAX_POINT;
        int min = 1;
        int max = 13;
        int guess = 0;
        System.out.println("High Low Game.");
        System.out.println("RULES.");
        System.out.println("1. Numbers 1 through 6 are low .");
        System.out.println("2. Numbers 8 through 13 are High .");
        System.out.println("3. Numbers 7 is neither high or Low.");
        do {
            displayPoints(point);
            int pointToRisk = enterPointsToRisk(point);
            String option = predictHiLo("\nPredict <1=High, 0=Low>: ");
            int computerRandomNum = randomNumgen(min, max);
            if (resultPoints(option, computerRandomNum)) {
                point += pointToRisk;
                guess += 1;
                System.out.println("You Win.");
            } else {
                point -= pointToRisk;
                guess += 1;
                System.out.println("You Lost.");
            }
            if(point == 0)  {
                System.out.println("It took "  + guess+" guesses to run out of points.");
                break;
            }
            if (point != 0) {
                continue;
            }
            else
            {
                System.out.println("It took "  + guess+" guesses to run out of points");
                System.out.println("See You Later!");
                break;
            }
        } while (point != 0);
    }
    
    public static void displayPoints(int point) {
        System.out.println("\nYou have " + point +" points.");
    }
    
    public static int randomNumgen(int min, int max) {
        int result = 1;
        Random rnd = new Random();
        result = rnd.nextInt(13 - 1 + 1) + 1;
        System.out.println("Number is " +result);
        return result;
    }
    public static int enterPointsToRisk(int point) {
        System.out.print("\nEnter Points to risk: ");
        Scanner in = new Scanner(System.in);
        int inputPoints = in.nextInt();
        if (inputPoints > point) {
            inputPoints = point;
        }
        return inputPoints;
    }
    
    public static String predictHiLo(String i) {
        String option = "";
        do {
            System.out.print(i);
            Scanner in = new Scanner(System.in);
            option = in.next();
        } while (!(option.equals("1") || option.equals("0")));
        return option;
    }
    
    public static boolean resultPoints(String option, int guessNumber) {
        boolean result = false;
        if (option.equals("1") && ((guessNumber >= 8) && (guessNumber <= 13))) {
            result = true;
            return result;
        } else if (option.equalsIgnoreCase("0") && ((guessNumber <= 6) && (guessNumber >= 1))) {
            result = true;
            return result;
        }
        else {
            return result;
        }
    }
}

 

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Random Class and its operations
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