import java.util.
Random;
import java.util.Scanner;
public class NumberGuessGame {
    private int numberToGuess;
    private int maxAttempts;
    private int attempts;
    public NumberGuessGame(int maxNumber, int maxAttempts) {
        this.numberToGuess = new Random().nextInt(maxNumber) + 1;
        this.maxAttempts = maxAttempts;
        this.attempts = 0;
    }
    public void play() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Welcome to the Number Guessing Game!");
        System.out.println("Try to guess the number between 1 and " + numberToGuess
+ " within " + maxAttempts + " attempts.");
        while (attempts < maxAttempts) {
            System.out.print("Enter your guess: ");
            int guess = scanner.nextInt();
            attempts++;
            if (guess == numberToGuess) {
                System.out.println("Congratulations! You guessed the number in " +
attempts + " attempts.");
                return;
            } else if (guess < numberToGuess) {
                System.out.println("Too low! Try again.");
            } else {
                System.out.println("Too high! Try again.");
            }
        }
        System.out.println("Game over! The correct number was: " + numberToGuess);
        scanner.close();
    }
    public static void main(String[] args) {
        NumberGuessGame game = new NumberGuessGame(100, 10);
        game.play();
    }
}