Would you please review and give me some feedback? I've been learning Java and I want to avoid bad practices.Is it good to make a helper class to define the methods my main program is using?Is this approach ok for bigger projects?If the game looks fine, what would be the next simple game challenge I should attempt? I'm not confident enough yet to mess with graphics.I'm new to GitHub, but I created my first repository today to upload this code, perhaps its easier to look at the code here.This is the main class:package game;import java.util.Scanner;import utils.GuessNumberUtils;public class GuessGame {    // Class with all the methods required by the game    static GuessNumberUtils numberGenerator = new GuessNumberUtils();    // Scanner to handle input    static Scanner keyboard = new Scanner(System.in);    // This is where we store the number to guess    static int numberToGuess;    // This is where we store the number guessed by the player    static int guessedNumber;    // Number of tries - the idea is to handle a scoring system in the future    static int tries;    // Flag used to loop the game    static boolean gameEnded = false;    // This is where we store the player's name    static String playerName;    public static void main(String[] args) {        // Asks for player's name        playerName = GuessNumberUtils.getPlayerName(keyboard);        while (!gameEnded) {            // We initialize the score (tries)            tries = 1;            // Generates a random number. To do: ask the players for the range            numberToGuess = numberGenerator.getRandomNumber(1, 100);            // Debugging only. Remove this line to actually play the game.            System.out.println(numberToGuess);            System.out.println(playerName                    + , I've picked a number between 1 and 100, guess it!);            guessedNumber = GuessNumberUtils.guessNumber(keyboard);            while (guessedNumber != numberToGuess) {                GuessNumberUtils.isNumberCorrect(numberToGuess, guessedNumber);                tries++;                guessedNumber = GuessNumberUtils.guessNumber(keyboard);            }            if (guessedNumber == numberToGuess) {                if (tries == 1) {                    System.out.println(Good job. You guessed it in 1 try.);                } else {                    System.out.println(Good job. You guessed it in  + tries                            +  tries.);                }            }            gameEnded = GuessNumberUtils.playAgain(keyboard);        }        keyboard.close();    }}This is the helper class I used to define methods:package utils;import java.util.Scanner;public class GuessNumberUtils {    /*     * Method to generate a random number in a specific range     */    public int getRandomNumber(int min, int max) {        return min + (int) (Math.random() * ((max - min) + 1));    }    /*     * Method to ask for the player's name     */    static public String getPlayerName(Scanner keyboard) {        String playerName;        System.out.println(Hi there! What's your name?);        playerName = keyboard.nextLine();        System.out.println(Hi  + playerName + , let's play!);        return playerName;    }    /*     * Method to ask for a number to guess.     */    static public int guessNumber(Scanner keyboard) {        System.out.println(Pick a number: );        return Integer.parseInt(keyboard.nextLine());    }    /*     * Method to check if the player has guessed the number.     */    static public boolean isNumberCorrect(int numberToGuess, int guessedNumber) {        if (numberToGuess == guessedNumber) {            return true;        } else {            if (numberToGuess < guessedNumber) {                System.out.println(Too high. Guess again.);            } else {                System.out.println(Too low. Guess again.);            }            return false;        }    }    /*     * Method to keep playing or finish it.     */    static public boolean playAgain(Scanner keyboard) {        char playAgain;        System.out.println(Play again? y/n);        playAgain = keyboard.nextLine().charAt(0);        while (playAgain != 'y' && playAgain != 'n') {            System.out.println(Please use 'y' for yes or 'n' for no.);            System.out.println(Play again? (y/n));            playAgain = keyboard.nextLine().charAt(0);        }        if (playAgain == 'n') {            System.out.println(Thanks for playing. Good bye!);            return true;        } else {            System.out.println(Let's play again!);            return false;        }    }}
Guess a number game in Java
java;game;number guessing game
First of all: I appreciate the clarity of your code. Variables have good names which causes the code to be read very fluently. Intendation, spacing and whitelines are also very well done so that's a major plus.Ofcourse, there are always working points. Let's take a look.Comments// This section will be about commentsThere, I clarified what this section was about. Well, actually I didn't because the title already conveyed that entire meaning. Which is exactly what you're doing with// This is where we store the number to guessstatic int numberToGuess;or// We initialize the score (tries)tries = 1;StaticYou're abusing the fact that the main method should be static and bypassing the OO rules of creating an object. Instead of using that main method directly as a part of your program, simply create an object of your surrounding class (GuessGame) and use instance variables instead. Additional benefit: you can now start multiple games at the same time.Static helper methodsA major advantage of a helpermethod is its ability to be called in a static context (aka: Utils.doSomething()). By forcing the user to create an instance of it, you're losing that usability. Aside from that, it also makes no sense to do that. Your helpermethod doesn't keep track of the state of anything, so there is never a difference between two instances.Lastly: stay consistent. 1 of your 4 util methods is an instance method.LinesplitsYou don't have to split this up:String playerName;System.out.println(Hi there! What's your name?);playerName = keyboard.nextLine();This is just fine and more readable because it doesn't force your brain to look into two places for no reason:System.out.println(Hi there! What's your name?);String playerName = keyboard.nextLine();Helper methodsAre they really necessary? The concept of helper methods is that they perform some tasks that can be used throughout multiple places in your project. You have one class so it's in fact impossible to have that situation. But even if you did have multiple: these methods are all specific to that one class so they belong as members to that class.ExceptionsThis line with invalid input, will cause your program to crash. You should add appropriate exception handling:return Integer.parseInt(keyboard.nextLine());NestingThis code is very nested:if(condition) {    return true;} else {    if(condition) {     }}I prefer a style that takes away some of this nesting (and thus allows more characters on your line):if(condition) {     return true;}if(condition) {}IndentationI told you before that I liked it, but after closer inspection I believe it's actually too far indented. There's an uncomfortable long white area:public int getRandomNumber(int min, int max) {        return min + (int) (Math.random() * ((max - min) + 1));}Indentation is done with 4 spaces (or 1 tab, consisting of 4 spaces). It's best to stick to these conventions.Order of attributesI see your methods are declared asstatic public boolean isNumberCorrect()It might be functionally the same, but once more popular convention dictates this instead (refer to the standard main method notation):public static boolean isNumberCorrect()I would back it up with the actual Java conventions, but for some reason that document has been offline for almost a few weeks by now.RedundancyPlease use 'y' for yes or 'n' for no.  Play again? (y/n)  This seems a little redundant. I suggest either removing the entire first line or, if you really want to keep it, to remove the y/n. But people know by now what y/n means so I'd prefer to simply remove the first line.Boolean is booleanWhen I look at a variable named playAgain, I expect it to tell me yes or no. I don't expect it to possibly tell me b.Therefore I suggest changing it to this:boolean playAgain = keyboard.NextLine().toLowerCase().startsWith(y);Notice how I also added toLowerCase() so Y is also accounted for, and used startsWith() to make the code more descriptive.It's ongoingThis is a very minor remark so feel free to ignore the advice it if you think it isn't important. Your while loop does this:while (!gameEnded)Maybe it's just me, but I'm a nitpicker and it doesn't have much feng shui to it. I would prefer to readwhile(!endOfGame)orwhile(running)Keep it short but readableWe can shorten this exhaustive block if (tries == 1) {    System.out.println(Good job. You guessed it in 1 try.);} else {    System.out.println(Good job. You guessed it in  + tries                            +  tries.);}toSystem.out.println(Good job. You guessed it in  + tries + (tries == 1 ?  try. :  tries.)); For such a small sentence, I would allow inlining that multiplication. The meaning is still conveyed clearly.