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; } } }
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;
}
}
}
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;
}
}
}
Step by step
Solved in 3 steps with 2 images