So my question is, that I'm getting the same error every time I want to start the Project in my console. I searched on Internet and I could get some Informations but their weren't helping much.
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at Zahlraten.main(Zahlraten.java:31)
This is my code I have been writing, it is a little game were the programm picks a number out of 1 to 100 and you need to give the programm the correct number. If you do that you win. I apologize because the Messages in the Code are written in German.
import javax.swing.*;
import java.util.Random;
import javax.swing.JOptionPane;
public class Zahlraten {
private int zufallszahl;
private int ratezahl;
Zahlraten() {
short 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) {
Zahlraten spiel = new Zahlraten();
boolean geraten = false;
int versuchzealer = 0;
JOptionPane.showMessageDialog(null,
"Erraten Sie eine ganze Zahl aus dem Bereich von 1 bis 100!");
Random randomGenerator = new Random();
spiel.setZufallszahl(randomGenerator.nextInt(101));
while (!geraten) {
spiel.setRatezahl(Integer.parseInt(
JOptionPane.showInputDialog("Welche Zahl wird gesucht?")));
versuchzealer++;
if (spiel.getRatezahl() < spiel.getZufallszahl()) {
JOptionPane.showMessageDialog(null, "Ihre Zahl ist zu klein!");
} else {
if (spiel.getRatezahl() > spiel.getZufallszahl()) {
JOptionPane.showMessageDialog(null, "Ihre Zahl ist zu groß!");
} else {
geraten = true;
JOptionPane.showMessageDialog(null,
"Glückwunsch! Sie haben die Zahl mit "
+ versuchzealer + " Versuchen erraten!");
}
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire