Question #277756

write a login system shall verify the username and password. If wrong username, please show the error message: Wrong username, please check and the re-enter your username. If wrong password, please show the error message: Wrong password, please check and re-enter your password.

Display message to ask the input from user (1 mark)

User name and password validation ( 2 marks)

Display the error message. (2 marks)

Proper use of loop so the user could re-enter the username/password when wrong input ( 2 marks)


1
Expert's answer
2021-12-09T17:37:24-0500


import java.util.Scanner;


public class App {


	/**
	 * The start point of the program
	 * 
	 * @param args
	 * 
	 */
	public static void main(String[] args) {
		Scanner keyBoard = new Scanner(System.in);
		final String correctUsername = "Admin";
		final String correctPassword = "1111";
		String username = "";
		do {
			System.out.print("Enter username: ");
			username = keyBoard.nextLine();
			if (username.compareTo(correctUsername) != 0) {
				System.out.println("\nWrong username, please check and the re-enter your username.\n");
			}
		} while (username.compareTo(correctUsername) != 0);


		String password = "";
		do {
			System.out.print("Enter password: ");
			password = keyBoard.nextLine();
			if (password.compareTo(correctPassword) != 0) {
				System.out.println("\nWrong password, please check and the re-enter your password.\n");
			}
		} while (password.compareTo(correctPassword) != 0);


		System.out.print("Successful login.");


		keyBoard.close();
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS