Hallo,
der Code geht so, hab ich getestet.
Aber Du hast noch andere Fehler
void vergleichen(){
richtige = 0; // initialisieren hast Du vergessen. sollte man machen
for(int i=0; i<6; i++){
for(int c=0; c<6; c++){
if(s_Zahl == Zahl[c]){
richtige++;
c=6;
}
}
}
System.out.println("Sie haben " +richtige +" Richtige ");
if (Superzahl == m_Super){
System.out.println("und die richtige Superzahl.");
} else {
System.out.println("jedoch die falsche Superzahl.");
}
}
Hier alles. Ich habe die Console rausgeschmissen, weil ich hier nichts eingebunden habe (Nullpointer)
Kannst Du nicht debuggen, dann hättest Du alle Fehler gefunden.
Und Variablen initialisieren wäre auch besser :idea: ich hab nicht alles angepasst, nur das nötigste
Werte zuweisen auch :idea:
Läuft so bei mir (Hab noch hier Kommentare eingebaut, hoffentlich ohne die Syntax zu versauen)
import java.io.BufferedReader;
import java.io.Console;
import java.io.InputStreamReader;
class Lottospiel {
int[] Zahl = new int[6];
int Superzahl;
int Spielnummer;
String m_Zahl[] = new String[6];
int s_Zahl[] = new int[6];
int m_Super;
int gewinnklasse;
int richtige;
double jackpot;
double gewinn;
boolean richtsuper ; // primitiven Datentyp genommen, sonst solltest Du new Boolean() machen
Lottospiel(int Schein) {
Spielnummer = Schein;
}
public void meinezahlen() {
try {
//Console cons = System.console();
BufferedReader cons = new BufferedReader(new InputStreamReader(System.in));
int help = 1;
for (int i = 0; i < 6; i++) {
System.out.printf("Bitte geben Sie Ihre " + help + ".Zahl ein:");
m_Zahl = cons.readLine();
s_Zahl = Integer.parseInt(m_Zahl);
if (s_Zahl > 49 || s_Zahl < 1) {
System.out.printf("Falsche Eingabe!");
i--;
help--;
}
System.out.printf("\n");
help++;
}
for (int b = 0; b < 1; b++) {
System.out.printf("Bitte geben Sie Ihre Superzahl ein:");
String einlesen = cons.readLine();
m_Super = Integer.parseInt(einlesen);
if (m_Super > 9 || m_Super < 0) {
System.out.printf("Falsche Eingabe! \n");
b--;
}
}
help = 1;
for (int i = 0; i < 6; i++) {
System.out.println("Ihre " + help + ". Zahl ist: " + m_Zahl);
help++;
}
System.out.println("Ihre Superzahl : " + m_Super);
System.out.printf("\n");
} catch (Exception e) {
System.err.println(e);
}
}
void lottoziehung() {
Zahl[0] = (int) (Math.random() * 48 + 1);
Zahl[1] = (int) (Math.random() * 48 + 1);
Zahl[2] = (int) (Math.random() * 48 + 1);
Zahl[3] = (int) (Math.random() * 48 + 1);
Zahl[4] = (int) (Math.random() * 48 + 1);
Zahl[5] = (int) (Math.random() * 48 + 1);
Superzahl = (int) (Math.random() * 6 + 1);
System.out.println("Die Lottozahlen:");
System.out.println("Gezogene Zahl : " + Zahl[0]);
System.out.println("Gezogene Zahl : " + Zahl[1]);
System.out.println("Gezogene Zahl : " + Zahl[2]);
System.out.println("Gezogene Zahl : " + Zahl[3]);
System.out.println("Gezogene Zahl : " + Zahl[4]);
System.out.println("Gezogene Zahl : " + Zahl[5]);
System.out.println("Superzahl : " + Superzahl);
}
void vergleichen() {
richtige = 0;
for (int i = 0; i < 6; i++) {
for (int c = 0; c < 6; c++) {
if (s_Zahl == Zahl[c]) {
richtige++;
c = 6;
}
}
}
System.out.println("Sie haben " + richtige + " Richtige ");
if (Superzahl == m_Super) {
System.out.println("und die richtige Superzahl.");
richtsuper = true; // Wert setzen
} else {
System.out.println("jedoch die falsche Superzahl.");
richtsuper = false; // Wert setzen, führt sonst in gewonnen() zu Fehlern
}
}
void gewonnen() {
if (richtsuper == true && richtige == 2) {
gewinnklasse = 9;
}
if (richtige == 3 && richtsuper == false) {
gewinnklasse = 8;
}
if (richtige == 3 && richtsuper == true) {
gewinnklasse = 7;
}
if (richtige == 4 && richtsuper == false) {
gewinnklasse = 6;
}
if (richtige == 4 && richtsuper == true) {
gewinnklasse = 5;
}
if (richtige == 5 && richtsuper == false) {
gewinnklasse = 4;
}
if (richtige == 5 && richtsuper == true) {
gewinnklasse = 3;
}
if (richtige == 6 && richtsuper == false) {
gewinnklasse = 2;
}
if (richtige == 6 && richtsuper == true) {
gewinnklasse = 1;
}
}
void gewinnrechnen() {
gewinn = 0.0;
if (gewinnklasse == 1) {
gewinn = (jackpot / 100) * 12.8;
}
if (gewinnklasse == 2) {
gewinn = ((jackpot / 100) * 10.0) / 9;
}
if (gewinnklasse == 3) {
gewinn = ((jackpot / 100) * 5.0) / 60;
}
if (gewinnklasse == 4) {
gewinn = ((jackpot / 100) * 15.0) / 2520;
}
if (gewinnklasse == 5) {
gewinn = ((jackpot / 100) * 2) / 6300;
}
if (gewinnklasse == 6) {
gewinn = ((jackpot / 100) * 10.0) / 129150;
}
if (gewinnklasse == 7) {
gewinn = ((jackpot / 100) * 8) / 172200;
}
if (gewinnklasse == 8) {
gewinn = ((jackpot / 100) * 44) / 2296000;
}
if (gewinnklasse == 9) {
gewinn = 5.0;
}
}
void ausgeben() {
// Console cons1 = System.console();
System.out.printf("Sie haben %.2f Euro gewonnen.", gewinn);
}
}