I am working on a simple ATM program and I am attempting to use an if/else statement to either stay in or exit a loop while inside a switch statement.
Here is my code so far:
while(continues == true)
{
System.out.println("Please select one of the following:\r\n"
+ "1 - Deposit\r\n"
+ "2 - Withdrawal\r\n"
+ "3 - Check Balance\r\n"
+ "4 - Log Out");
accountChoice = menuChoice.nextByte();
switch(accountChoice)
{
case 1:
System.out.println("How much would you like to Deposit?");
depositAmt = deposit.nextDouble();
bob.deposit(depositAmt);
System.out.println("Thank you, your current balance "
+ " is $" + bob.getBalance());
System.out.println("Do you want to make another "
+ "transaction?");
yesNo = yN.next();
if(yesNo == "Y" || yesNo == "y")
{
System.out.println("You will make another transaction");
continues = true;
break;
}
else
{
System.out.println("You will not make another transaction");
continues = false;
break;
}
case 2:
System.out.println("You chose Withdrawal");
break;
case 3:
System.out.println("You chose Check Balance");
break;
case 4:
System.out.println("You chose Log Out");
continues = false;
break;
}// end switch
}// end while loop
My output is "You will not make another transaction" followed by my program ending regardless of what I actually enter. My problem seems to be that the else statement is always picked, but I do not know why.
Any help would be greatly appreciated.