Hi all,
I'm having a bit of a problem with a simple program I cooked up for practice. The code is below:
Java Code:
import java.util.Scanner;
public class CAPPLogin {
public static void main(String[] args) {
/* This program is designed to take two string inputs from the user simultaneously
* and check them against two preset string values. If the inputs match, the user
* will receive an "Access Granted" message. If one or both of the inputs do not
* match, the user will receive one of three self-written error messages (not an exception)
* that will each be output depending on the scenario.
*/
Scanner scan = new Scanner(System.in);
System.out.println("Thank you for activating CAPP Employee LogIn Launcher.");
System.out.print("Username: ");
String username = scan.nextLine();
System.out.print("Password: ");
String password = scan.nextLine();
if (username == "Employee1" && password == "bli33ard")// If both the username and password match the preset strings
{
System.out.println("Processing...");
System.out.println("Account recognized. Welcome Michael.");
}
else if(username != "Employee1")// If the username does not match the preset string
{
System.out.println("Processing...");
System.out.println("Error: Username not recognized.");
}
else if(password != "bli33ard")// If the password does not match the preset string
{
System.out.println("Processing...");
System.out.println("Error: Password not recognized.");
}
else if (username != "Employee1" && password != "bli33ard")// If both the username and password do not match the preset strings
{
System.out.println("Processing...");
System.out.println("The specified account does not exist.");
}
}
}
(Just so you know, I use Eclipse for my programs.)
Like I said, this program is just for practice and isn't intended for anything other than learning Java.
I am having no trouble at all running the program itself, there are no critical errors. It's just whenever I do run it, and input the correct "log-in info," it gives me the error message "Error: Username not recognized." This is odd, as I have checked the program itself and my input.
If it's a simple oversight, like it probably is, forgive me as I am quite new to Java.
Also, if anyone has feedback on how I could improve the program itself, that would be very much appreciated
No comments:
Post a Comment