So my program asks two questions, directions and miles. A user can enter an infinite input for direction and miles, but once the user is done he would simply type "Done" and the loop would break and show the message and the end. I can't get the loops to break need help. Also when a letter is typed for numOfMiles the program just ends. It's suppose to give the error message and reprompt but i can't seem to get that working.
import javax.swing.JOptionPane;
public class taxiService {
public static void main(String [] args) {
//Declare variables
double fareCharge = 5;
double totalMiles = 0;
double finalFareCharged = 0;
double finalxCoord = 0;
double finalyCoord = 0;
double numOfMiles = 0;
double finalCoord = 0;
String error = "Invalid data, please enter valid data!";
String directions = "";
boolean restart = true;
//Prompt for direction and miles
while(restart){
boolean reprompt = true;
boolean reprompt_SecondQuestion = true;
while (reprompt) {
directions = JOptionPane.showInputDialog(null, "Please enter a direction: ");
if (directions.equalsIgnoreCase("East")) {
finalxCoord = finalxCoord + numOfMiles;
reprompt = false;
}
else if (directions.equalsIgnoreCase("West")) {
finalxCoord = finalxCoord - numOfMiles;
reprompt = false;
}
else if (directions.equalsIgnoreCase("North")) {
finalyCoord = finalyCoord + numOfMiles;
reprompt = false;
}
else if (directions.equalsIgnoreCase("South")) {
finalyCoord = finalyCoord - numOfMiles;
reprompt = false;
}
else {
reprompt = true;
JOptionPane.showMessageDialog(null, error);
}
}
while(reprompt_SecondQuestion)
{
numOfMiles = Double.parseDouble(JOptionPane.showInputDialog(null, "Please enter distance in miles: "));
if (numOfMiles > 0) {
totalMiles += numOfMiles;
reprompt_SecondQuestion = false;
}
else {
JOptionPane.showMessageDialog(null, error);
}
}
//Prompt user to type "done"
//Capture user input
if(directions.equalsIgnoreCase("Done"))
{
//Display direction and miles to user
restart = false;
break;
}
else
{
}
}
finalFareCharged = fareCharge + ((numOfMiles / .25) * 2);
JOptionPane.showMessageDialog(null, "miles: " + totalMiles + "\nDirection :" + directions + "\nFinal Charge: " + finalFareCharged + "\nCoordination: " + finalCoord);
}
}
I was able to use this to stop the looping problem
while(done) {
end = JOptionPane.showInputDialog(null, "Is this your destination?(YES/NO)");
if (end.equalsIgnoreCase("Yes")) {
restart = false;
reprompt = false;
reprompt_SecondQuestion = false;
done = false;
break;
}
else if (end.equalsIgnoreCase("No")) {
restart = true;
done = false;
}
else{
JOptionPane.showMessageDialog(null, error);
done = true;
}
}
i still got a problem with numOfMiles. if a letter is entered the program ends. it doesn't give the error message. i've added reprompt_SecondQestion = true; but no change.
I would use labeled break statement (so the intention would be clear for the future reader of the code). Here is the example which prints s0-1-2-3e:
...
System.out.print("s");
labelName:
while (true) {
for (int i = 0; i < 5; i++) {
System.out.print(i);
if (i == 3) {
break labelName; // the "thing" you are looking for
}
}
System.out.print("-");
}
System.out.print("e");
...
This means that you only need to add the label label: and condition statement:
if (directions.equalsIgnoreCase("Done")) {
break label;
}
Your task now, is just to find a proper places to put the code.
Check the condition of your loop. Something like this would suffice:
if(directions.equalsIgnoreCase("Done"))
{
//Display direction and miles to user
reprompt_SecondQuestion = false;
reprompt = false;
restart = false;
break;
}
Also I cannot tell from the brackets where this block is located, if it is at all within the loop. Please check, as proper formatting will save you hours.
Related
I'm trying to loop these two questions("please enter direction") AND ("Please enter distance in miles"). If incorrect value is inputed then it will reprompt the user to enter a correct value. So these two questions will loop until the user is done entering and a "Destination" is reached. I got the first question to loop if the user doesn't type north east south or west, but the second question I could only make it loop on itself.
boolean reprompt = true;
//Prompt for direction and miles
while (reprompt) {
directions = JOptionPane.showInputDialog(null, "Please enter a direction: ");
if (directions.equalsIgnoreCase("East")) {
finalxCoord = finalxCoord + numOfMiles;
reprompt = false;
}
else if (directions.equalsIgnoreCase("West")) {
finalxCoord = finalxCoord - numOfMiles;
reprompt = false;
}
else if (directions.equalsIgnoreCase("North")) {
finalyCoord = finalyCoord + numOfMiles;
reprompt = false;
}
else if (directions.equalsIgnoreCase("South")) {
finalyCoord = finalyCoord - numOfMiles;
reprompt = false;
}
else {
reprompt = true;
JOptionPane.showMessageDialog(null, error);
}
}
numOfMiles = Double.parseDouble(JOptionPane.showInputDialog(null, "Please enter distance in miles: "));
if (numOfMiles > 0) {
totalMiles += numOfMiles;
JOptionPane.showMessageDialog(null, "miles: " + totalMiles);
}
else
JOptionPane.showMessageDialog(null, error);
Just make the second question inside a while loop with another boolean just as you did for the first question.
Code:
boolean restart = true;
//Prompt for direction and miles
while(restart){
boolean reprompt = true;
boolean reprompt_SecondQuestion=true;
while (reprompt) {
directions = JOptionPane.showInputDialog(null, "Please enter a direction: ");
if (directions.equalsIgnoreCase("East")) {
finalxCoord = finalxCoord + numOfMiles;
reprompt = false;
}
else if (directions.equalsIgnoreCase("West")) {
finalxCoord = finalxCoord - numOfMiles;
reprompt = false;
}
else if (directions.equalsIgnoreCase("North")) {
finalyCoord = finalyCoord + numOfMiles;
reprompt = false;
}
else if (directions.equalsIgnoreCase("South")) {
finalyCoord = finalyCoord - numOfMiles;
reprompt = false;
}
else {
reprompt = true;
JOptionPane.showMessageDialog(null, error);
}
}
while(reprompt_SecondQuestion)
{
numOfMiles = Double.parseDouble(JOptionPane.showInputDialog(null, "Please enter distance in miles: "));
if (numOfMiles > 0) {
totalMiles += numOfMiles;
JOptionPane.showMessageDialog(null, "miles: " + totalMiles);
reprompt_SecondQuestion = false;
}
else
{
JOptionPane.showMessageDialog(null, error);
}
}
//Prompt user to type "done"
//Capture user input
if(user_input.equals("Done"))
{
//Display direction and miles to user
restart = false;
}
else
{
}
}
Alright, I have a class assignment to create 3 predetermined methods for a rock, paper, scissors program written by the teacher. However, when I run the program it running the methods multiple times in a row. I've looked through the code several times and can't figure out the problem.
Below is the teacher provided portion of the program:
public class Game
{
public static void main (String[] args)
{
Scanner in = new Scanner (System.in);
RockPaperScissors rps = new RockPaperScissors (); //***Your class
int numGames = 0;
String userChoice = "";
String cpuChoice = "";
String winner = "";
int userWins = 0;
int cpuWins = 0;
System.out.println("Welcome to Rock, Paper, Scissors!\n");
//Get odd number of games
System.out.println("How many rounds would you like to play?");
numGames = in.nextInt();
while (numGames % 2 == 0) //Even number
{
System.out.println("Sorry, number of games must be odd. Please try again:");
numGames = in.nextInt();
}
//Flush the buffer
in.nextLine();
//Play the game for the number of rounds the user entered
for (int i = 1; i <= numGames; i++)
{
//Get the user and computer choices
userChoice = rps.getUserChoice(); //***Your method
cpuChoice = rps.getCPUChoice(); //***Your method
System.out.println("Computer chooses " + cpuChoice);
//Pick winner
winner = rps.pickWinner(userChoice, cpuChoice); //***Your method
if (winner.equalsIgnoreCase("Tie"))
{
System.out.println("It's a tie! Play again.");
numGames++;
}
else
{
if (winner.equalsIgnoreCase("User"))
{
userWins++;
}
else if (winner.equalsIgnoreCase("Computer"))
{
cpuWins++;
}
else
{
System.out.println("Error in picking winner");
}
System.out.println(winner + " wins!");
}
} //end for
//Print results
System.out.println("\nUser wins: " + userWins);
System.out.println("Computer wins: " + cpuWins);
if (userWins > cpuWins)
{
System.out.println("\nThe user won!");
}
if (cpuWins > userWins)
{
System.out.println("The computer won!");
}
//Close game
System.out.println("\nThank you for playing!");
} //end main
} //end class
And here is my code which I'm assuming where the problem is coming from:
public class RockPaperScissors {
public String getUserChoice() {
Scanner sc = new Scanner (System.in);
System.out.println("Enter your choice:");
String userInput = sc.nextLine();
boolean end = true;
while (end == true){
//Checks for valid user responses
if (userInput.equals("rock") || userInput.equals("paper")|| userInput.equals("scissors")){
end = false;
}
else {
System.out.println("Invalid response. Please enter rock paper or scissors:");
userInput = sc.next();
}
}
return userInput;
}// end getUsechoice
public String getCPUChoice() {
String computerChoice = " ";
Random rand = new Random();
int randomNum = rand.nextInt(3) + 1;
if (randomNum == 1){
computerChoice = "rock";
}
else if (randomNum == 2){
computerChoice = "paper";
}
else if (randomNum == 3){
computerChoice = "scissors";
}
return computerChoice;
}
public String pickWinner(String userChoice, String cpuChoice) {
String result = " ";
if (getUserChoice().equalsIgnoreCase("rock")) {
if (getCPUChoice().equalsIgnoreCase("rock")){
result = "tie";
}
else if (getCPUChoice().equalsIgnoreCase("paper")){
result = "Computer";
}
else if (getCPUChoice().equalsIgnoreCase("scissors")){
result = "User";
}
}
else if (getUserChoice().equalsIgnoreCase("paper")){
if (getCPUChoice().equalsIgnoreCase("paper")){
result = "tie";
}
else if (getCPUChoice().equalsIgnoreCase("rock")){
result = "User";
}
else if (getCPUChoice().equalsIgnoreCase("scissors")){
result = "Computer";
}
}
else if (getUserChoice().equalsIgnoreCase("Scissors")){
if (getCPUChoice().equalsIgnoreCase("scissors")){
result = "tie";
}
else if (getCPUChoice().equalsIgnoreCase("rock")){
result = "Computer";
}
else if (getCPUChoice().equalsIgnoreCase("Paper")){
result = "User";
}
}
return result;
}//end pickWinner
}//end rockPaperScissors
Here would be a sample session of the program:
Welcome to Rock, Paper, Scissors!
How many rounds would you like to play? 1 Enter your choice: rock
Computer chooses paper Enter your choice: rock Enter your choice: rock
Computer wins!
User wins: 0 Computer wins: 1 The computer won!
Thank you for playing!
Here I'm wondering why it continues asking for user input multiple times. Also it runs the other methods as well which is why the computer won despite picking paper vs rock.
Alright added in the final changes to my program and it's working perfectly now:
public String pickWinner(String userChoice, String cpuChoice) {
String result = " ";
if (userChoice.equalsIgnoreCase("rock")) {
if (cpuChoice.equalsIgnoreCase("rock")){
result = "tie";
}
else if (cpuChoice.equalsIgnoreCase("paper")){
result = "Computer";
}
else if (cpuChoice.equalsIgnoreCase("scissors")){
result = "User";
}
}
else if (userChoice.equalsIgnoreCase("paper")){
if (cpuChoice.equalsIgnoreCase("paper")){
result = "tie";
}
else if (cpuChoice.equalsIgnoreCase("rock")){
result = "User";
}
else if (cpuChoice.equalsIgnoreCase("scissors")){
result = "Computer";
}
}
else if (userChoice.equalsIgnoreCase("Scissors")){
if (cpuChoice.equalsIgnoreCase("scissors")){
result = "tie";
}
else if (cpuChoice.equalsIgnoreCase("rock")){
result = "Computer";
}
else if (cpuChoice.equalsIgnoreCase("Paper")){
result = "User";
}
}
return result;
}//end pickWinner
The problem seems to be that when I called in getCPUChoice or getUserChoice it would rerun the program and then change the final answers.
You calling getUserChoice() in the pickWinner method. It should be the userChoice method parameter you should be checking.
public String pickWinner(String userChoice, String cpuChoice) {
String result = " ";
if (userChoice.equalsIgnoreCase("rock")) {
if (cpuChoice.equalsIgnoreCase("rock")){
result = "tie";
}
else if (cpuChoice.equalsIgnoreCase("paper")){
result = "Computer";
}
else if (cpuChoice.equalsIgnoreCase("scissors")){
result = "User";
}
}
else if (userChoice.equalsIgnoreCase("paper")){
if (cpuChoice.equalsIgnoreCase("paper")){
result = "tie";
}
else if (cpuChoice.equalsIgnoreCase("rock")){
result = "User";
}
else if (cpuChoice.equalsIgnoreCase("scissors")){
result = "Computer";
}
}
else if (userChoice.equalsIgnoreCase("Scissors")){
if (cpuChoice.equalsIgnoreCase("scissors")){
result = "tie";
}
else if (cpuChoice.equalsIgnoreCase("rock")){
result = "Computer";
}
else if (cpuChoice.equalsIgnoreCase("Paper")){
result = "User";
}
}
return result;
You should ask for user input in each loop and not just once.
public class RockPaperScissors {
public String getUserChoice() {
Scanner sc = new Scanner (System.in);
System.out.println("Enter your choice:");
//not here
String userInput;
while (true){
//this is the right place
userInput = sc.nextLine();
//Checks for valid user responses
if (userInput.equals("rock") || userInput.equals("paper")|| userInput.equals("scissors")){
break;
}
else {
System.out.println("Invalid response. Please enter rock paper or scissors:");
}
}
return userInput;
}// end getUsechoice
//...
}//end rockPaperScissors
try changing this in your else part
userInput = sc.next();
to this
userInput = sc.nextLine();
So it will go to next line
So the resulting code ll be
while (end == true){
//Checks for valid user responses
if (userInput.equals("rock") || userInput.equals("paper")|| userInput.equals("scissors")){
end = false;
}
else {
System.out.println("Invalid response. Please enter rock paper or scissors:");
userInput = sc.nextLine();
}
}
My task is to enter names into an array. If the name has already been entered, the program must alert about that and offer to reenter the player under the same number.
This is my code:
public void enterNames() {
for (int i=0; i<nameOfPlayers.length; i++)
{
do
{
// isDuplicate is a Boolean initialized to false
System.out.println("CHECK": + isDuplicate);
System.out.println("Enter player " + (i+1) + ":");
nameOfPlayers[i] = in.next();
for (int k=0; k<nameOfPlayers.length; k++)
{
if (k!=i && nameOfPlayers[i].equals(nameOfPlayers[k]))
{
isDuplicate = true;
break;
}
}
} while (isDuplicate = false);
}
}
Interesting, even when I enter a duplicate value, it is caught and assigns true to isDuplicate, but when it returns to the beginning of the while loop, the value is false again ("CHECK: false").
Looks like an easy task, but I am caught...
Also, I did not want to use HashSet and wanted to use only Array.
Thanks a lot!
EDIT:
Thanks to others, I rewrote the code to the following:
public void enterNames() {
List<String> nameOfPlayersList = new ArrayList<String>();
int i = 0;
for (i=0; i<numberOfPlayers;)
{
while(true)
{
System.out.println("Enter player " + (i+1) + ":");
String input = in.next();
if(!nameOfPlayersList.contains(input))
{
nameOfPlayersList.add(input);
i++;
break;
}
System.out.println("Player " + input + " already exists, please retry");
}
}
}
Answer reformed, used List to add more and more elements without pre defined size.
changed while (isDuplicate == false); to while (!isDuplicate);
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
List<String> nameOfPlayers = new ArrayList<String>();
boolean isDuplicate = false;
int i = 0;
do {
System.out.println("Enter player " + (i + 1) + ": or Q for Quit");
String input = scanner.next();
if (!input.equalsIgnoreCase("Q")) {
if (nameOfPlayers.contains(input)) {
isDuplicate = true;
} else {
nameOfPlayers.add(input);
isDuplicate = false;
}
System.out.println("CHECK : " + isDuplicate);
} else {
break;
}
i++;
} while (!isDuplicate);
}
Enter player 1: or Q for Quit
ankur
CHECK : false
Enter player 2: or Q for Quit
singhal
CHECK : false
Enter player 3: or Q for Quit
ankur
CHECK : true
The problem you are having is because of the
} while (isDuplicate = false);
it should be (mind the double ==)
} while (isDuplicate == false);
Apart from that your code is quite inefficient. You would probably do much better with two Arrays if that is really what you want, otherwise a linked list would be best.
Your while is incorrect, this
while (isDuplicate = false);
assigns false to isDuplicate which has a side-effect of also evaluating to false. You watned something like
while (isDuplicate == false);
or the shorter
while (!isDuplicate);
How do I convert my do-while loop to a while loop?
int numAttempts = 0;
do
{
System.out.println("Do you want to convert to Peso or Yen?");
pesoOrYen = readKeyboard.nextLine();
if(pesoOrYen.equalsIgnoreCase("Peso")||pesoOrYen.equalsIgnoreCase("Yen"))
{
notPesoOrYen = false;
}
else if (numAttempts < 2)
{
System.out.println("Sorry, but '"+pesoOrYen+"' is not a valid currency type. Try again:");
notPesoOrYen = true;
}
numAttempts++;
} while(notPesoOrYen==true && numAttempts < 3);
I tried to do while(notPesoOrYen==true && numAttempts < 3) then the statement but it did not work.
MY FULL CODE
package currencyconverter;
import java.util.Scanner;
import java.text.NumberFormat;
public class CurrencyConverter
{
public static void main(String[] args)
{
Scanner readKeyboard = new Scanner(System.in);
double doubleUsersCaptial;
boolean notPesoOrYen=true;
String pesoOrYen;
double usersConvertedCapital;
boolean userInputToRunProgramAgain=true;
final double US_DOLLAR_TO_PESO = 13.14;
final double US_DOLLAR_TO_YEN = 106.02;
do
{
System.out.println ("How much money in US dollars do you have?");
String usersCaptial = readKeyboard.nextLine();
doubleUsersCaptial = Double.parseDouble(usersCaptial);
int numAttempts = 0;
do
{
System.out.println ("Do you want to convert to Peso or Yen?");
pesoOrYen = readKeyboard.nextLine();
if(pesoOrYen.equalsIgnoreCase("Peso")||pesoOrYen.equalsIgnoreCase("Yen"))
{
notPesoOrYen = false;
}
else if (numAttempts < 2)
{
System.out.println("Sorry, but '"+pesoOrYen+"' is not a valid currency type. Try again:");
notPesoOrYen = true;
}
numAttempts++;
}while(notPesoOrYen==true && numAttempts < 3);
if(numAttempts==3)
{
System.out.println("Sorry, but '"+pesoOrYen+"' is not a valid currency type.");
System.out.println("You entered the wrong currency type too many times\nGood Bye");
System.exit(0);
}
if (pesoOrYen.equalsIgnoreCase("Peso"))
{
usersConvertedCapital = doubleUsersCaptial*US_DOLLAR_TO_PESO;
}
else
{
usersConvertedCapital = doubleUsersCaptial*US_DOLLAR_TO_YEN;
}
NumberFormat formatter = NumberFormat.getCurrencyInstance();
String formatUsersCaptial = formatter.format(doubleUsersCaptial);
String formatUsersConvertedCapital = formatter.format(usersConvertedCapital);
System.out.println(formatUsersCaptial+"US Dollars = "
+formatUsersConvertedCapital+" "+pesoOrYen);
System.out.println("Would you like to run the Program Again?(enter 'yes' or 'no')");
String runProgramAgain = readKeyboard.nextLine();
if (runProgramAgain.equalsIgnoreCase("yes"))
{
userInputToRunProgramAgain = true;
}
else if (runProgramAgain.equalsIgnoreCase("no"))
{
System.out.println("Goood Bye");
System.exit(0);
}
else
{
System.out.println ("You entered something other than 'yes' or 'no'\n"
+"Good Bye");
System.exit(0);
}
}while (userInputToRunProgramAgain==true);
}
}
while and do... while are almost the same, do... while simply performs an iteration before evaluating for the first time the exit condition, whereas while evaluates it even for the first iteration (so eventually the body of a while loop can never be reacher whereas a do... while body will always be executed at least once).
Your code snippet is not complete but I guess you didn't initialized notPesoOrYen to true before the loop and that's why it is not working. Finally, don't write while(notPesoOrYen==true && numAttempts < 3) but while(notPesoOrYen && numAttempts < 3), the == true comparison is unnecessary.
Initialise your boolean variable outside while loop:
int numAttempts = 0;
boolean notPesoOrYen=true;
while (notPesoOrYen && numAttempts < 3) {
System.out.println("Do you want to convert to Peso or Yen?");
pesoOrYen = readKeyboard.nextLine();
if (pesoOrYen.equalsIgnoreCase("Peso") || pesoOrYen.equalsIgnoreCase("Yen")) {
notPesoOrYen = false;
} else if (numAttempts < 2) {
System.out.println("Sorry, but '" + pesoOrYen + "' is not a valid currency type. Try again:");
notPesoOrYen = true;
}
++numAttempts;
};
import java.util.Scanner;
import javax.swing.JOptionPane;
public class Coin {
public static void main(String[] args)
{
boolean validFinalInput = false;
boolean validBetInput = false;
boolean validGuessInput = false; //Determines if the guess is a valid input
boolean validBet = false; //Determines if the bet is valid
boolean goAgain = true;
double num; //Unparsed Side Determiner
double balance = 100;
String Bet = null; //Bet Input
double bet = 0; //Parsed Bet
String Guess = null; //H or T
String Side = null; //Determines Side
String GoAgain = null; //Y/N Retry input
Scanner in = new Scanner(System.in);
while (goAgain == true){ //While true, the player will keep playing.
num = Math.round(Math.random()); //Declares Number
if (num == 1){
Side = "H";
} else if (num == 0){
Side = "T";
}
while (validGuessInput == false){ //Determines if the input is valid
System.out.println("Guess: (H/T)");
Guess = in.next();
if (Guess.equals("H") || Guess.equals("T")){
validGuessInput = true;
} else {
JOptionPane.showMessageDialog(null, "Invalid Guess!");
validGuessInput = false;
}
}
while (validBet == false){
while (validBetInput == false){
try {
System.out.println("Bet? (Your balance is $" + balance);
Bet = in.next();
bet = Double.parseDouble(Bet);
if (bet > 0){
validBetInput = true;
}
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "Invalid Bet!");
}
}
if (bet <= balance && bet >= 0){
validBet = true;
} else {
JOptionPane.showMessageDialog(null, "Invalid Bet!");
validBet = false;
}
}
if (Guess.equals(Side)){
balance = balance + (bet * 2);
System.out.println("Correct! The side was: " + Side);
System.out.println("Your balance is now: $" + balance);
} else {
balance = balance - bet;
System.out.println("Incorrect! The side was: " + Side);
System.out.println("Your balance is now: $" + balance);
}
if (balance == 0){
System.out.println("You ran out of money. Ending Game.");
break;
}
System.out.println("Go again? (Y/N)");
GoAgain = in.next();
while (validFinalInput == false);
System.out.println("Go again? (Y/N)");
GoAgain = in.next();
validGuessInput = false;
validBet = false;
validBetInput = false;
if (GoAgain.equals("Y")){
goAgain = true;
validFinalInput = true;
} else if (GoAgain.equals("N")){
goAgain = false;
validFinalInput = true;
System.out.println("Thanks for playing! You ended with: $" + balance);
} else {
System.out.println("Invalid Input!");
}
}
}
}
So I wrote this code for a "Heads or Tails" style game. It originally worked, but then I decided to add a few features, and it busted. Basically, it gets to the end, but is stuck on the last input (Y/N).
Could someone show me what I'm doing wrong?
Sorry for the lack of commenting.
I also am aware my variables don't quite follow conventions, so sorry for that too.
Thanks.
Remove the semicolon here;
while (validFinalInput == false);
Indent your code properly.
Check your logic here; You are setting validFinalInput = true for both the conditions (true and false).
if (GoAgain.equals("Y")){
.........
validFinalInput = true; }
else if (GoAgain.equals("N")){
.......
validFinalInput = true; }
The value of goAgain never changes in the loop that starts with while (goAgain == true){ because it ends with the } just before while (validBet == false){. That closing bracket is misplaced.
You have this while statement
while (validFinalInput == false);
This is an infinite loop! it will never get past this part of the code because of the semicolon. If you rewrite it like this it should work:
while (validFinalInput == false)
{
System.out.println("Go again? (Y/N)");
GoAgain = in.next();
validGuessInput = false;
validBet = false;
validBetInput = false;
if (GoAgain.equals("Y"))
{
goAgain = true;
validFinalInput = true;
}
else if (GoAgain.equals("N"))
{
goAgain = false;
validFinalInput = true;
System.out.println("Thanks for playing! You ended with: $" + balance);
}
else
{
System.out.println("Invalid Input!");
}
}