Question

First, launch NetBeans and close any previous projects that may be open (at the top menu...

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 3 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." A loop is not needed for this program.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.*;

public class PasswordChecker

{

    public static boolean ifValid(String pwd)

    {

        // If it is not 3 characters in length

        if(pwd.length() != 3)

            return false;

       

        int i, digit = 0, upper_case = 0;

       

        for( i = 0 ; i < pwd.length() ; i++ )

        {

            // get the ascii code of the current character

            int ascii = (int)pwd.charAt(i);

           

            // if the current character is a digit

            if( ascii >= 48 && ascii <= 57 )

                digit++;

            // if the current character is upper case

            else if( ascii >= 65 && ascii <= 90 )

                upper_case++;

        }

       

        // Include at least one uppercase character

        // Include at least one digit

        if( digit > 0 && upper_case > 0 )

            return true;

        else

            return false;

    }

   

    public static void main(String[] args)

    {

        // store the password from the command line argument

        String pwd = args[0];

       

        // create a Scanner object

        Scanner sc = new Scanner(System.in);

       

        if(ifValid(pwd))

            System.out.println("The provided password is valid.");

        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.");

    }

}

Sample Output

Users userDesktop>javac PasswordChecker.java Users\user Desktop>java PasswordChecker Ab9 The provided password is valid Users

Add a comment
Know the answer?
Add Answer to:
First, launch NetBeans and close any previous projects that may be open (at the top menu...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • "PhoneNumberConversion" First, launch NetBeans and close any previous projects that may be open (at the top...

    "PhoneNumberConversion" 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 "PhoneNumberConversion" (without the quotation marks) based on the Horstmann textbook chapter 2 programming exercise called Business, P 2.23 on page 75, in the section on Programming Exercises near the end of Chapter 2, before the answers to the self-check questions. Request the ten-digit phone number from the user at...

  • First, launch NetBeans and close any previous projects that may be open (at the top menu...

    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 "MultiDimensions" (without the quotation marks) that declares a two-dimensional array of doubles (call it scores) with three rows and three columns and that uses methods and loops as follows. Use a method containing a nested while loop to get the nine (3 x 3) doubles from the user at the...

  • First, launch NetBeans and close any previous projects that may be open (at the top menu...

    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 "MinMax" (without the quotation marks) that declares an array of doubles of length 5, and uses methods to populate the array with user input from the command line and to print out the max (highest) and min (lowest) values in the array. The methods that determine the max and min...

  • Please make this Python code execute properly. User needs to create a password with at least...

    Please make this Python code execute properly. User needs to create a password with at least one digit, one uppercase, one lowercase, one symbol (see code), and the password has to be atleast 8 characters long. try1me is the example I used, but I couldn't get the program to execute properly. PLEASE INDENT PROPERLY. def policy(password): digit = 0 upper = 0 lower = 0 symbol = 0 length = 0 for i in range(0, len(password)): if password[i].isdigit(): # checks...

  • Write a program that inputs a string from the user representing a password, and checks its...

    Write a program that inputs a string from the user representing a password, and checks its validity. A valid password must contain: -At least 1 lowercase letter (between 'a' and 'z') and 1 uppercase letter (between 'A' and 'Z'). -At least 1 digit (between '0' and '9' and not between 0 and 9). At least 1 special character (hint: use an else to count all the characters that are not letters or digits). -A minimum length 6 characters. -No spaces...

  • Python Create a function that checks user input in an attempt to create a password. The...

    Python Create a function that checks user input in an attempt to create a password. The valid_password function accepts a password as an argument and returns either true or false to indicate whether the password is valid. A valid password must be at least 7 characters in length, have at least one uppercase letter, one lowercase letter, and one digit. Respond with output to the user as to whether the password is valid or not, and allow the user to...

  • Keeping this code written as close to this as possible and only using these headers. How...

    Keeping this code written as close to this as possible and only using these headers. How do I turn this in to a code that can read from 3 files of passwords then sort them into two files. One for valid passwords and the other for invalid passwords and then send a message to the user that says how many are valid and how many are invalid. Only using std::ifstream fin; fin.open("data.txt"); fin.close(); std::ofstream fout; fout.open("data.txt"); fout.close(); #include <iostream> #include...

  • In C Write a function that asks for the user's first, middle, and last names. The...

    In C Write a function that asks for the user's first, middle, and last names. The names will be entered by the user on a single line and will be stored in three different C-strings. The program should then store, in a fourth array, the name arranged in the following manner: the last name followed by a comma and a space, followed by the first name and a space, followed by the middle name. For example, if the user entered...

  • Password Validation Write a program called PasswordValidationYourLastName that validates a new password, following these guidelines: Must...

    Password Validation Write a program called PasswordValidationYourLastName that validates a new password, following these guidelines: Must be at least 8 characters Must have at least 1 uppercase letter Must have at least 1 lowercase letter Must have at least 1 digit Write a program that asks for a password, and then asks again to confirm it (you can use the scanner or JOptionPane). Pass those two Strings to a method called validatePassword( ). Your validatePassword( ) should return a boolean...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT