0

The Java code I am running is asking the user for their user name(which is stored in the string variable UserNameForLogIn) and password(which is stored in the string variable PasswordForLogIn) and if it is the same as the other UserName and Password that is already stored in a String variable at the beginning of the code the condition for a while loop will be meet and it enters it and starts looping but the problem is even if the user puts the exact User name and password from the UserName and Password String Variables from the start of the code it still doesn't want to the while loop as if the condition has not been meet. Please, anyone, I need help this is a part of my school project that I'm doing and it's due in 3 days theirs still 2 more errors in other parts of my code that I still need to fix before I can put it all together in one file. Thank you in advance to anyone who can help me.

here is the code and what I tried to do please note it's also doing the same thing in both case 1 and case 2 where they confirm your new password.

import java.util.*;
class Main {
  public static void main(String[] args) {


    StartUp();
  }

  static void StartUp()
  {
    int option;
    String UserName = "KalemJoffe";
    String Password = "Staria01";
    String UserNameForLogIn;
    String PasswordForLogIn;
    String UserNameForSignUp;
    String PasswordForSignUp;
    String PasswordForSignUp2;
    
    Scanner input = new Scanner(System.in);

    System.out.println("Welcome to the banking app please select a option: ");

    System.out.println("1. Log In");
    System.out.println("2. Sign Up");
    option = input.nextInt();
    //Now I am creating a switch statement that will do specific commands depending on their option: Note the correct password and Email for Log In option is at the top//
    
    switch(option){

      case 1 : 
        System.out.println("Please enter UserName : ");
        UserNameForLogIn = input.nextLine();
        
        input.nextLine();
        System.out.println("Please enter password: ");
        PasswordForLogIn = input.nextLine();

       while (UserNameForLogIn  == UserName && PasswordForLogIn == Password)
        {
         System.out.println("Weclome");
          
        
        }
 
       System.out.println(" Your Email or password is wrong please try again: ");
         
         System.out.println("Please enter email : ");
         UserNameForLogIn = input.nextLine();

         System.out.println("Please enter password: ");
         PasswordForLogIn = input.nextLine();
        
    

        break;

       case 2 :
        System.out.println("Please enter your new email: ");
         UserNameForSignUp = input.nextLine();
         input.nextLine();
        System.out.println("Please create a password: ");
        PasswordForSignUp = input.nextLine();
       
        System.out.println("Pleae confirm your password: ");
        PasswordForSignUp2 = input.nextLine();

        while (PasswordForSignUp != PasswordForSignUp2 ){

         System.out.println("Error your passwords do not aline please try again! ");
         System.out.println("Please create a password: ");
          
         PasswordForSignUp = input.nextLine();
         System.out.println("Pleae confirm your password: ");
         PasswordForSignUp2 = input.nextLine();
         
        }
    }
    
   }
}
user238795
  • 47
  • 5

0 Answers0