So I started learning Java newly, and I made my own program. When I am trying to run it, I am getting wrong replies/outputs. The code is below:
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner myInpObj = new Scanner(System.in);
System.out.println("Hello There! Welcome to Planet KVSK Airlines! Which date you wanna book? \nNote: Since this is a new airline, we have flights for today and tomorrow only. Please mention exactly whether 1 or 2 respectively.");
String bookingDate = myInpObj.nextLine();
if (bookingDate == "1") {
System.out.println("Oh, thats great! You wanna book for today? Where do you wanna go? We have Delhi & Sydney, Australia.");
String placeToGo = myInpObj.nextLine();
if (placeToGo == "Delhi") {
System.out.println("We have flight at 9:00pm today, which is 3 hours. Do you wanna book it? Since it is our maiden flight, you will get free meals! Price is ₹5000.\nReply with Yes or No.");
String Delhi_Book_9pm_Confirm = myInpObj.nextLine();
if (Delhi_Book_9pm_Confirm == "No") {
System.out.println("No problem, have a good day!");
}
else if (Delhi_Book_9pm_Confirm == "Yes") {
System.out.println("Thanks! Your ticket is booked, please input 'Select Seats' to select your required seats.\n Note: Please book your tickets separately, for each passenger if there is more than 1 person travelling.");
String select_seats = myInpObj.nextLine();
if (select_seats == "Select Seats") {
System.out.println("We have seats - \n1\n2\n\n3\n5\n10\n18\n22\n31 \nThis flight is kinda full, btw!\n Tell the seat number you wanna book!");
String seat_number = myInpObj.nextLine();
System.out.println("Done! Flight BOOKED! Thanks for choosing Planet KVSK Airlines, have a good day!");
}
}
}
else {
System.out.println("Flight at 11:15pm today and is filling fast! One-stop via Singapore, and costs ₹48,926. Okay or Not Okay?");
String sydney_bookConfirm = myInpObj.nextLine();
if (sydney_bookConfirm == "Not Okay") {
System.out.println("Next Time, see ya!");
}
else {
System.out.println("Booking confirmed! Seat selection at airport counters only. Have a great flight ahead & thanks for choosing Planet KVSK Airlines!");
}
}
}
else {
System.out.println("Oh, amazing! Our current destinations for tomorrow are Leh and New York.");
String placeToGo2 = myInpObj.nextLine();
if (placeToGo2 == "Leh") {
System.out.println("There is a flight waiting for you at 9:30pm tomorrow! It's a 1 stop flight via Delhi. Price is ₹5000. Yes, or No?");
String leh_930_bookConfirm = myInpObj.nextLine();
if (leh_930_bookConfirm == "No") {
System.out.println("It's okay, next time maybe! Have a good day!");
}
else {
System.out.println("Recieved your money with thanks! Book you seat now, by typing 'Seat Select'\nIf more than 1 passenger is travelling, then book the ticket again and select seats again.");
String seat_select2 = myInpObj.nextLine();
if (seat_select2 == "Seat Select") {
System.out.println("Since this is an ATR and seats are almost full, we have - \n21\n2\n18\n23\n12\nInput Seat number you wanna book!");
String seat_number2 = myInpObj.nextLine();
System.out.println("Seat BOOKED! Thanks for choosing Planet KVSK Airlines, see you tomorrow!");
}
}
}
else {
System.out.println("We have a flight at 4:25am tomorrow. Two-stop flight, Dubai and Paris. Price is ₹70,525. Make sure to have your VISA handy! Yes or no?");
String ny_book_confirm = myInpObj.nextLine();
if (ny_book_confirm == "No") {
System.out.println("No problem, see ya!");
}
else {
System.out.println("Payment confirmed and received. Seat booking is only available at the airport counter. Please be present 5 hours before boarding. Thanks for choosing Planet KVSK Airlines!");
}
}
}
}
}
When I try to input 1, its going for 2 and vice versa. Same for all other inputs, like when I input Leh, it's going for Sydney. But for the "YES" or "NO" question asked in the end, it's working fine, but just sometimes. It's really weird imo. Can someone please help me?