Okay, so the actual question is really lengthy, so I'm only going to give the information that you need to know:
1. I'm launching a projectile over a wall.
2. After each launch, the user has to be able to choose whether to play again or quit.
The variables I use (that you need to know):
boolean GameOn
int angle;
int speed;
String choice;
You should also probably know that my scanner is called `sc`
So this is what's happening (read the comments):
while (GameOn = true)
Wall myWall = new Wall();
System.out.println(myWall.toString());
System.out.print("Thus, enter this angle and speed.");
angle = sc.nextInt();
speed = sc.nextInt();
if ((myWall.reach(angle, speed) - myWall.getHeight())>= 4) {
score+=2;
System.out.println("You went a little too far over but good job!");
System.out.println("Do you want to play again or quit?");
choice = sc.nextLine();
System.out.println("it passes the choice");
if (choice == "play again") {
myWall.setNewWall();
}
else if (choice == "quit") {
GameOn = false;
break;
}
}
And here is where my problem is! For some reason, rather than the program waiting for the user to type in their choice, my program creates a new wall! It just skips right over
choice = sc.nextLine();
for some reason!
Do you know why? Can someone please help? And please tell me if you need me to include my full code. My original code isn't very long but this version is quite fragmented so you only get the main point.
Once again please please please help. I've been stuck on this for the past three days and my project is due soon. Thank you so much if you can help!
What I have tried:
what have I tried? See above for the code which I have tried!