Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

226
Visualizações
Java - Cannot Use Class From Same Directory

I'm trying to call the Game class (that resides in src/main/java/Game.java) from within the Main class (that resides in src/main/java/Main.java), but I'm getting this error:

Main.java:3: error: cannot find symbol Game hangman = new Game(); symbol: class Game; location: class Main::: Main.java:3: error: cannot find symbol Game hangman = new Game(); symbol: class Game; location: class Main::: 2 errors; error: compilation failed

Here is the code that is in the Main.java file:

public class Main {
  public static void main (String[] args) {
    Game hangman = new Game();
    hangman.initialize();
  }
}

Here is the code that is in the Game.java file:

public class Game {
  private String randomWord;
  private int maxGuesses;
  private int guessCount;

  public Game () {
    this.maxGuesses = 8;
    this.guessCount = 0;
  }

  public void incrementGuessCount () {
    this.guessCount++;
  }

  public String generateRandomWord () {
    String[] words = {"puppy", "pool", "avalanche"};
    String result = words[(int) Math.floor(Math.random() * words.length)];
    this.randomWord = result;
    return result;
  }

  public void initialize () {
    String word = this.generateRandomWord();
    System.out.println(word);
  }
}

I'm using WSL, and this is my current Java version.

openjdk 11.0.13 2021-10-19 OpenJDK Runtime Environment (build 11.0.13+8-Ubuntu-0ubuntu1.20.04) OpenJDK 64-Bit Server VM (build 11.0.13+8-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda