I am trying to take user input and ask if the user wants to enter the gamer's information. if "yes" then take the info and if "no" then exit the program.
My code is working well except that when I am asking the user for the second time and enter "no", it is not exiting the program but instead is asking again for the gamer's name.
import java.util.Scanner;
public class A3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String name;
double L1, L2, L3, ES;
boolean yes = true
System.out.println("Welcome to the Total XP calculation program!");
System.out.print("Do you want to enter gamer's data? Yes/No => ");
String y_n= sc.nextLine();
while (yes = true) {
if (y_n.equals("yes") || y_n.equals("Yes")) {
System.out.print("Enter gamer's name: ");
name = sc.next();
System.out.println("Enter gamer's Level XP scores separated by space: L1 L2 L3 ES => ");
L1 = sc.nextDouble();
L2 = sc.nextDouble();
L3 = sc.nextDouble();
ES = sc.nextDouble();
// calculating total score
double score = L1+L1*0.20+L2+L2*0.30+L3+L3*0.50+ES+ES*0.60;
// printing informations.
System.out.println("Gamer's name: "+name + " L1 = "+L1 + " L2 = " +L2 + " L3 = " +L3 + " ES = " +ES);
System.out.println("Final XP score with bonuses= "+score);
System.out.println("\nDo you want to enter another gamer's data? Yes/No => ");
String choice;
sc.nextLine();
choice = sc.nextLine();
switch (choice) {
case "no" :
case "No" :
System.out.println("Thank you for using the Total XP calculator!");
yes = false;
}
}
else if (y_n.equals("no") || y_n.equals("No")) {
System.out.println("Thank you for using the Total XP calculator!");
break;
}
}
}
}