import java.util.Scanner; public class Guesser { private int low; private int high; private Scanner keyboard; public Guesser() { this.low = 1; this.high = 100; this.keyboard = new Scanner(System.in); } public void guess() { int middle = (low + high) / 2; System.out.print("Is the number greater than " + middle + "? "); String answer = keyboard.nextLine(); if(answer.charAt(0) == 'y' || answer.charAt(0) == 'Y') { low = middle + 1; } else { high = middle; } } public void run() { System.out.println("Think of a number between 1 and 100 and I'll guess it."); while(low < high) { guess(); } System.out.println("The number is " + low + "!"); } public static void main(String[] args) { Guesser engine = new Guesser(); engine.run(); } }