package task3;

import java.util.Scanner;

public class NumberGuesser {
    private int number;

    public NumberGuesser(int targetNumber){
        this.number = targetNumber;
    }
    public boolean isBigger(int guess){
        return guess < number;
    }

    public void guess(){
        Scanner scanner = new Scanner(System.in);
        System.out.println("Guess a number: ");
        int guess = scanner.nextInt();
        switch (Integer.compare(guess, number)) {
            case -1 -> System.out.println("Too low!");
            case 0 -> System.out.println("Correct!");
            case 1 -> System.out.println("Too high!");
        }
    }

    public void autoGuess(){
        int low = Integer.MIN_VALUE;
        int high = Integer.MAX_VALUE;

        while (low <= high) {
            int mid = low + (high - low) / 2;

            System.out.println("Guess: " + mid);
            if (mid == number) {
                return;
            } else if (isBigger(mid)) {
                low = mid + 1;
            } else {
                high = mid - 1;
            }
        }
    }

    public static void main(String[] args) {
        NumberGuesser numberGuesser = new NumberGuesser(100);
        System.out.println(numberGuesser.isBigger(Integer.MAX_VALUE/2));
        numberGuesser.autoGuess();
    }
}
