Hi! I'm fairly new to Java and as ridiculous as this sounds, I'm having a difficult time wrapping my head around methods and how to execute them.
For example, right now I'm making a game for class where the user guesses a number that a random generator pulls up. It's in one class right now called numbersTester but I want to have two classes (numbers and numbersTester) where numbers have the methods. I attempted to do this myself but I didn't know how to pull up the code in numbersTester correctly so I just put it in one class.
Any feedback/help would be appreciated!
import java.util.Random;
import java.util.Scanner;
public class NumbersTester extends Numbers {
public static void main(String[] args) {
Random number = new Random();
int numberToGuess=number.nextInt(100);
Scanner input = new Scanner (System.in);
boolean win = false;
int numberOfTries = 0;
int guess;
while (win == false){
System.out.println("Guess a number between 1 and 100: ");
guess = input.nextInt();
numberOfTries ++;
if (guess == numberToGuess){
win = true;
}
if (guess > 100 || guess < 0){
System.out.println("Invalid number!");
}
else if (guess < numberToGuess){
System.out.println("The number is too low! Guess again.");
}
else if (guess > numberToGuess){
System.out.println("The number is too high! Guess again.");
}
}
System.out.println("\n" + "Game Over! " + "\n" + "You guessed correctly.");
System.out.println("The answer was: " + numberToGuess);
System.out.println(numberOfTries + " tries.");
}
}