Q:

write java program to check login info of the user, program should do that using a method called login

0

write java program to check login info of the user, program should do that using a method called "login", its inputs are username and password, and its output is a boolean value indicates if login info is correct or wrong

hint, in the login method you should use equals() method to compare between Strings

user have 3 try times to enter his login his username and password.

 

output should be like this:

your login info, you have remaining 3 try times
username: 
adam 
password: 
1234567
login info is wrong, you have 2 try times remaining
your login info, you have remaining 2 try times
username: 

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.util.Scanner;
public class Main
{
    public static boolean login(String username,String password)//function declaration
    {
        //function body:
        String correctUsername="ads2100",correctPassword="987763";
        if(username.equals(correctUsername) && password.equals(correctPassword))
        return true;
        else return false;
    }
    
	public static void main(String[] args) {
	    Scanner input=new Scanner(System.in);
	    int remainingTryTimes=3;
	    String u,p;
	    boolean result;
	    do{
	        System.out.println("your login info, you have remaining "+remainingTryTimes+" try times");
	        System.out.println("username: ");
	        u=input.next();
	        System.out.println("password: ");
	        p=input.next();
	        result=login(u,p);
	        if(result==true)
	        {
	            System.out.println("login info is correct, you will signin now...");
	            System.out.println("welcome "+u);
	            break;
	        }
	        else {
	            remainingTryTimes--;
	            System.out.println("login info is wrong, you have "+remainingTryTimes+" try times remaining");
	        }
	    }
	    while(remainingTryTimes>0);
	}
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now