Question: Hello, can someone help me with a problems for my java code merrySeven. between line 124 and 139, I want to ask the player if
Hello, can someone help me with a problems for my java code merrySeven. between line 124 and 139, I want to ask the player if he/she wants to continue the game. In line 125 Im asking the player Do you want to end (Y)? if he wants to end than the total money should be calculatet (line 135-139). I know updateBalance is not correct right now but my prolem is when the user wants to continue so he/she is answering with "n" than the whole programm should start from the beginning. But how can I handle this because the while (true) statement before try catch, dont let me out of the loop. And breaks the programm because I have no return value. How do I have to adjust my program to repeatedly ask the player for more inputs so starting with line 19. Greetings.
import java.io.*; public class Aufgabe03_1 {
final static int[] TABLE1= { 2, 4, 9, 6, 11 }; final static int[] TABLE2= { 3, 5, 8, 10, 12 }; public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int balance = 0; int updateBalance = 0; int win = 0; int bet = 0; int guess = 0;
Out.println("Hallo bei Lustige Sieben."); Out.println("====================================== "); Out.println("Bitte Deinen Einsatz zwischen 1 und 100: "); while(true) { String input = new String(); // for reading Strings while(true) { try { input = br.readLine(); bet = Integer.parseUnsignedInt(input); if (bet 100) { throw new Exception(); } } catch (Exception e) { Out.println("Falscher Einsatz! Bitte Deinen Einsatz zwischen 1 und 100: "); continue; } break; } Out.println(String.format("Du setzt %d, damit ist Dein Kontostand = %d " ,bet , -bet)); Out.println("Bitte Deine Zahl zwischen 2 und 12: "); String input2 = new String(); while(true) { try { input2 = br.readLine(); guess = Integer.parseUnsignedInt(input2); if (guess 12) { throw new Exception(); } } catch (Exception e) { Out.println("Falsche Zahl! Bitte Deine Zahl zwischen 2 und 12: "); continue; } break; } // Roll the dice int dice1 = (int)(Math.random() * 6) +1; int dice2 = (int)(Math.random() * 6) +1; int dicethrow = dice1 + dice2; System.out.format("Die Wrfel sind gefallen: %d + %d = %d ", dice1, dice2, dicethrow); // Possibilities for updating the balance based on dicethrow and bet, storage into the win variable! // Special dice Situation where the user can get twice or thrice times the bet back if ( guess == dicethrow ) { if ( guess == 7 ) { win = 3 * bet; // Refait --> win thrice } else { win = 2 * bet; // dicethrow is equal to guess number --> win twice } } // If dicethrow is 2,4,6,9,11 --> Search in the left table side if the guess number is on the left table as well. if ( dicethrow == 2 || dicethrow == 4 || dicethrow == 6 || dicethrow == 9 || dicethrow == 11 ) { for ( int i = 0; i Search in the right table side if the guess number is on the right table as well. if ( dicethrow == 3 || dicethrow == 5 || dicethrow == 8 || dicethrow == 10 || dicethrow == 12 ) { for (int i = 0; i 0 ) { System.out.format("Du bekommst zurck: %d ", bet); } else { System.out.format("Du hast Deinen Einsatz von %d verloren ", bet); } System.out.format("Dein neuer Kontostand = %d ", updateBalance); while (true) { System.out.print("Willst du aufhren (Y)? "); try { input = br.readLine().toUpperCase(); } catch (Exception e) { throw new Exception(); } if (input.equals("N")) { // Wie komm ich hier wieder zum Anfang? boolean wird immer verhindert wegen while (true), Was kann ich als return setzen? System.out.println("--------------------------------------"); return; } else if (input.equals("Y") || input.isEmpty()) { System.out.println("--------------------------------------"); System.out.format("Dein Endstand = %d ", updateBalance); System.out.println("======================================"); return; } } } } }



1 import java.io.*; 2 public class Aufgabe03 1 1 5 final static int[] TABLE2- 3, 5, 8, 10, 12 ; 7 public static void main (Stringl] args) throws Exception final static int[] TABLE1= { 2, 4, 9, 6, 11 }; 8 BufferedReader br new BufferedReader (new InputStreamReader(System.in)); int balance e; int updateBalance 0 int win; int bet - 0; int guess e; 10 12 13 14 15 16 Out.println( Hallo bei Lustige Sieben."); 17 Out.println(" Out.printin("Bitte Deinen Einsatz zwischen 1 und 18a: "); 19 while(true) 20 String input new String) 21 while(true) { 2 try for reading Strings 23 24 25 26 27 28 29 38 31 32 input- br.readLine); bet-Integer.parseUnsignedInt (input); if (bet
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
