Question: Java : Ending program MerrySeven I found now my first mistake and I have to fight only with the last method now. printEndStatement(). When I
Java : Ending program MerrySeven I found now my first mistake and I have to fight only with the last method now. printEndStatement(). When I want to end the game so the player puts y/Y it shows me the end balance but my program never stops, so its reasking again. How do I have to change my program to avoid this.

before I could use a do while loop so the program stoped because of this 
Code
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader;
public class Test { final static int[] TABLE1 = { 2, 4, 9, 6, 11 }; final static int[] TABLE2 = { 3, 5, 8, 10, 12 }; static int updateBalance = 0; static int win = 0; static int bet = 0; static int guess = 0; public static void main(String[] args) { System.out.println("Hallo bei Lustige Sieben."); System.out.println("====================================== ");
while (true) { try { readBet(); updateBalance(); readGuess(); //diceLogic(); testWin(); printBalance(); printEndStatement();
} catch (Exception e) { System.out.println(e.getMessage());
} } } public static int readBet() { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Bitte Deinen Einsatz zwischen 1 und 100: "); //Please place your bet between 1 and 100:
while (true) { try {
String input = new String(); input = br.readLine(); bet = Integer.parseInt(input);
if (bet 100) { throw new Exception(); }
} catch (Exception e) {
System.out.println("Falscher Einsatz! Bitte Deinen Einsatz zwischen 1 und 100: "); continue; // Wrong bet! Please playe your bet between 1 and 100 } break; } return bet; }
public static int readGuess() { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println(" Bitte Deine Zahl zwischen 2 und 12: "); // Please play your number between 2 and 12 while (true) { try {
String input = new String(); input = br.readLine(); guess = Integer.parseInt(input);
if (guess 12) { throw new Exception(); }
} catch (Exception e) { System.out.println("Falsche Zahl! Bitte Deine Zahl zwischen 2 und 12: "); continue; // Wrong number! Please place your number between 2 and 12 } break; } return guess; } public static int updateBalance() { // You placed %d , your new balance is now = %d System.out.println(String.format("Du setzt %d, damit ist Dein Kontostand = %d", bet, updateBalance - bet)); return updateBalance;
}
public static int testWin() { return win = 20; //this is only for test }
public static int printBalance() { if (win > 0) { updateBalance = updateBalance - bet + win; System.out.format("Du bekommst zurck: %d ", win); } if (win
return updateBalance;
}
public static void printEndStatement() throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String input = new String(); System.out.print("Willst du aufhren (Y)? "); //Do you want to end?
input = br.readLine().toUpperCase();
while (!(input.equals("Y") || input.equals("N"))) { System.out.print("Willst du aufhren (Y)? "); //Do you want to end? input = br.readLine().toUpperCase();
}
if (input.equals("N")) { System.out.println("--------------------------------------");
} else if (input.equals("Y") || input.isEmpty()) { System.out.println("--------------------------------------"); System.out.format("Dein Endstand = %d ", updateBalance); //End Balance System.out.println("======================================"); //After print the program should } //terminate } }
--> What can I do in my last else if statement to correct the mistake that my program never stops? Everyhting works now fine. This is the last difficulty I have now left.
1129.RI o : 4:46" T. f ] D Aufgabe03-1 ja a D Aufgabe04-1 ja a 23 D MerrySe enga a D Aufgabe022javaBank java Playerja a 2 Testjea Variables X 00 Breakpoints tExpressons 152 153 return Min; G printinD returned br e input No explicit BufferedRea... 'V' (id=41) 155 public static int printBalance) 156 157 158 if (win > e) { updateBalance-pdateBalance System.out.format("Du bekomst bet win; zurck: %d ", win); if(win
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
