0

I have coded a little program and when I tried to compile it, I got 9 error messages. And also I qam very sorry for the Language. It is german. So if you know German maybe help me. I just started with coding. I hope that I can learn from you talented programmers. Thanks darkwastaken Errors are:

Zahlraten.java:13: error: class Zahlraten is public, should be declared in a file named Zahlraten.java
public class Zahlraten {
       ^
Zahlraten.java:38: error: cannot find symbol
    var spiel = new Zahlraten();
    ^
  symbol:   class var
  location: class Zahlraten
Zahlraten.java:39: error: cannot find symbol
    var geraten = false;
    ^
  symbol:   class var
  location: class Zahlraten
Zahlraten.java:40: error: cannot find symbol
    var versuchszaehler = 0;
    ^
  symbol:   class var
  location: class Zahlraten
Zahlraten.java:42: error: cannot find symbol
    var randomGenerator = new Random();
    ^
  symbol:   class var
  location: class 

Zahlraten.java:43: error: cannot find symbol
    spiel.setZufallszahl(randoGenerator.nextInt(101));
                         ^
  symbol:   variable randoGenerator
  location: class Zahlraten

Zahlraten.java:45: error: no suitable method found for showMessageDialog(String)
        spiel.setRatezahl(Integer.parseInt(JOptionPane.showMessageDialog("Welche Zahl wird gesucht?")));
                                                      ^
    method JOptionPane.showMessageDialog(Component,Object) is not applicable
      (actual and formal argument lists differ in length)
    method JOptionPane.showMessageDialog(Component,Object,String,int) is not applicable
      (actual and formal argument lists differ in length)
    method JOptionPane.showMessageDialog(Component,Object,String,int,Icon) is not applicable
      (actual and formal argument lists differ in length)
Zahlraten.java:46: error: cannot find symbol
    versuchzaehler++;
    ^
  symbol:   variable versuchzaehler
  location: class Zahlraten
Zahlraten.java:51: error: cannot find symbol
        JOptionPane.shwoMessageDialog(null, "Ihre Zahl ist zu Groß!");
                   ^
  symbol:   method shwoMessageDialog(<null>,String)
  location: class JOptionPane
these are the 9 errors
* Zahlenraten Mini Edition
* @version 1.20
* @date 2020-12-31
* @author Dark
*/

package ratespiel;

import java.util.Random;
import javax.swing.JOptionPane;

public class Zahlraten {
    private int zufallszahl;
    private int ratezahl;
    
Zahlraten() {
    ratezahl = -1;
}

void setZufallszahl(int zahl) {
    zufallszahl = zahl;
}

int getZufallszahl() {
    return zufallszahl;
}

void setRatezahl(int zahl) {
    ratezahl = zahl;
}

int getRatezahl() {
    return ratezahl;
}

public static void main(String[] args) {
    var spiel = new Zahlraten();
    var geraten = false;
    var versuchszaehler = 0;
    JOptionPane.showMessageDialog(null, "Erraten Sie eine Zahl zwischen 1 und 100");
    var randomGenerator = new Random();
    spiel.setZufallszahl(randoGenerator.nextInt(101));
    while (!geraten) {
        spiel.setRatezahl(Integer.parseInt(JOptionPane.showMessageDialog("Welche Zahl wird gesucht?")))
    versuchzaehler++;
    if (spiel.getRatezahl() < spiel.getZufallszahl()) {
        JOptionPane.showMessageDialog(null, "Ihre Zahl ist zu Klein!");
} else {
    if (spiel.getRatezahl() > spiel.getZufallszahl()) {
        JOptionPane.shwoMessageDialog(null, "Ihre Zahl ist zu Groß!");
} else {
    geraten = true;
    JOptionPane.showMessageDialog(null, "Glückwunsch! Sie haben die Zahl nach + versuchszaehler + Versuchen erraten!");
    }
   }
  }
 }
}```
Anton Pomieshchenko
  • 2,051
  • 2
  • 10
  • 24
  • 1
    So you want to guess a number but get errors and now you want *us* to guess the errors? Please provide specific error details, what kind of errors, on what line, etc. – luk2302 Feb 03 '21 at 14:25
  • I edited the Question. Sorry for that I am like I said, very very new to this topic. – darkwastaken Feb 03 '21 at 14:34
  • What about the first one *"class Zahlraten is public, should be declared in a file named Zahlraten.java"* - is it in a file called `Zahlraten.java`? – luk2302 Feb 03 '21 at 14:37
  • no, the files name is Zahlraten.java – darkwastaken Feb 03 '21 at 14:38
  • Okay, `versuchszaehler` != `versuchzaehler`, `randoGenerator` != `randomGenerator`, `var` does not exist, what java version are you targeting, obviously not the right one since the compilter does not understand `var` yet. `JOptionPane.showMessageDialog(...)` does not work for only a `String` argument, etc. All these errors are pretty clear, you simply need to work through them. – luk2302 Feb 03 '21 at 14:47
  • That was very helpful, Thank you and have a nice Day/Night! – darkwastaken Feb 03 '21 at 14:51
  • I updated both Java and the Compiler. Now everything works with your help. Thank you to all of you. – darkwastaken Feb 03 '21 at 14:58

0 Answers0