In: Computer Science
First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ==> Close All Projects). Then create a new Java application called "PasswordChecker" (without the quotation marks) that gets a String of a single word from the user at the command line and checks whether the String, called inputPassword, conforms to the following password policy. The password must: Be exactly three characters in length Include at least one uppercase character Include at least one digit If the password conforms to the policy, output "The provided password is valid." Otherwise, output "The provided password is invalid because it must be three characters in length and include at least one digit and at least one uppercase character. Please try again." Some other points to remember... Do not use a loop in this program.
The Character class offers various methods to assist us in finding a digit or cased letter. Remember to press "." to locate these methods and to leverage the online resources shown in our course thus far." For this PA, do not use pattern matching (aka "regular expressions").
import java.lang.Character; //importing the Character
class
class PasswordChecker{
public static void main(String[] args)
{
String inputPassword = new String
(args[0]); //constructing "inputPassword" from command line
argument
if
(inputPassword.length()==3)
{
//Constructing 3
variable since loops cannot be used using the Character constructor
(we know the length to be 3)
Character ch1 =
new Character (inputPassword.charAt(0)); //hence we can initialize
like this from 0-2
Character ch2 =
new Character (inputPassword.charAt(1));
Character ch3 =
new Character (inputPassword.charAt(2));
//if statement
to check if input conforms to the password policy
if (
(Character.isUpperCase(ch1) || Character.isUpperCase(ch2) ||
Character.isUpperCase(ch3)) && (Character.isDigit(ch1) ||
Character.isDigit(ch2) || Character.isDigit(ch3)))
{
System.out.println("The provided password is
valid.");
}
//else password
is invalid
else
System.out.println("The provided password is invalid because it
must be three characters in length and include at least one digit
and at least one uppercase character. Please try again.");
}
//else password is invalid
else System.out.println("The
provided password is invalid because it must be three characters in
length and include at least one digit and at least one uppercase
character. Please try again.");
}
}