Code:
import java.io.*;
public class Playself
{
public static void main(String args[]) throws IOException, NumberFormatException
{
int x = (int)(1000 * Math.random()) + 1;
int g1, g2, g3, g4, g5, g6, g7, g8, g9, g10;
int timesplayed;
int max;
int min;
double average;
BufferedReader IN = new BufferedReader(new InputStreamReader(System.in));
int upper, lo, hi, count, guess;
boolean again = false;
String input;
timesplayed = 0;
max = 0;
min = 0;
average = 0;
System.out.println(" Guessing Game ");
do
{
timesplayed++;
do
{
System.out.print("\nWould you like to view the instructions, (y)es or (n)o? ");
input = IN.readLine();
if (input.equals("y") || input.equals("Y"))
{
System.out.println("\n\tYou will set an upper bound and think of a number between");
System.out.println("\t1 and that number. I will try to guess your number in as");
System.out.println("\tfew guesses as possible.");
}
} while (!(input.equals("y") || input.equals("Y") || input.equals("n") || input.equals("N")));
System.out.print("\nEnter the upper bound: ");
upper = Integer.parseInt(IN.readLine());
System.out.println();
count = 0;
lo = 1;
hi = upper;
guess = (upper / 2);
do {
System.out.print("\tMy guess is " + (hi+lo)/2 + ". Is that (l)ow, (h)igh, or (c)orrect? ");
input = IN.readLine();
if ((hi+lo)/2 == hi || (hi+lo)/2 == lo) {
System.out.println("\tCHEATER!!!!!!!!!!!!!!!!!!!!!!!!!!!");
break; }
count++;
switch(input.charAt(0)){
case 'l':
case 'L':
lo = (hi + lo) / 2;
break;
case 'h':
case 'H':
hi = (hi + lo) / 2;
break;
case 'c':
case 'C':
System.out.println("\n\tI guessed your number in only " + count + " tries!");
System.out.println("\nThank you for playing Guessing Game.");
break;
}
} while (!(input.equals("c") || input.equals("C")));
System.out.print("\nPlay again? (Y)es or (N)o: ");
String goAgain = IN.readLine();
if (goAgain.equals("y") || goAgain.equals("Y"))
{
again = true;
}
else
{
again = false;
}
if (timesplayed == 1)
{
max = count;
min = count;
average = count;
}
else
{
if (count > max)
{
max = count;
}
else if (count < min)
{
min = count;
}
average = (timesplayed - 1 * average) + count / timesplayed;
}
} while (again == true);
System.out.println("\nThank you for playing Guessing Game!");
System.out.println("\nStatistics:");
{
System.out.println("\n\tTimes played: " + timesplayed);
System.out.println("\tLowest number of guesses: " + min + " guesses.");
System.out.println("\tHighest number of guesses: " + max + " guesses.");
System.out.println("\tAverage number of guesses: " + average + " guesses.");
}
}
}
After it has chosen the number the comp will ask the comp guess my number. the comp should guess a random number to start with and comp will say low high or correct. It should also say how amny times it took.
so yeah i need some advice like where to start. PLZ DONT GIMME THE WHOLE CODE i wnna try this myself since i have the weekend to do it (today and tomorrow). If you want snippets of code are helped but yeah i just really want to no where to start and what i should do im very confused.