Question

In: Computer Science

Valid or Invalid Password Deliverables • Complete one document that shows your planning (IPO Chart). Include...

Valid or Invalid Password Deliverables

• Complete one document that shows your planning (IPO Chart). Include in it Input, Processing, Output, Variables, Algorithm, Testing Conditions

• Complete the code for your method and test it then upload for grading

Requirements: Write a Java method to check whether a string is a valid password.

Password rules: A password must have at least ten characters.

A password consists of only letters and digits.

A password must contain at least two digits.

Expected Output:

1. A password must have at least eight characters.

2. A password consists of only letters and digits.

3. A password must contain at least two digits Input a password (You are agreeing to the above Terms and Conditions.): abcd1234 Password is valid: abcd1234

Solutions

Expert Solution

Java Program:

   import java.util.Scanner;

   public class ValidatePassword
   {
       public static void main(String[] args)
       {
           //To hold the user's input
           String a, b;
          
           //A Scanner object for keyboard input.
           Scanner a1 = new Scanner(System.in);
          
           System.out.println("\n 1. A password must have at least eight characters. \n 2. A password consists of only letters and digits.");
           System.out.print(" 3. A password must contain at least two digits \n\n Input a password (You are agreeing to the above Terms and Conditions.): ");
           //Prompt the user to enter the password.
           a = a1.next();
          
           // Validating for length
           if(a.length() >= 8)
           {
               int letters = 0, digits = 0, specials = 0;
              
               // Iterating over string
               for(int i=0; i<a.length(); i++)
               {  
                   //Checking for letters
                   if( Character.isLetter(a.charAt(i)) )
                   {
                       letters += 1;
                   }
                  
                   //Checking for digits
                   else if( Character.isDigit(a.charAt(i)) )
                   {
                       digits += 1;
                   }
                  
                   //Checking for special symbols
                   else
                   {
                       specials += 1;
                   }
               }
              
               //Validating combination of characters
               if(specials > 0)
               {
                   System.out.println("\n\n Error!!! Password should be a combination of only Letters, Digits but not special symbols... \n");
               }
               //Combination error
               else if(digits < 2)
               {
                   System.out.println("\n\n Error!!! Password should contain at-least 2 digits... \n");
               }
               else
               {
                   System.out.println("\n\n Password is Valid: " + a + " \n\n");
               }
           }
           //Length error
           else
           {
               System.out.println("\n Error!!! Password length should be minimum eight characters \n");
           }
       }
   }

_______________________________________________________________________________________________________

Sample Run:


Related Solutions

Create two arguments, one valid and one invalid. Demonstrate with a truth table the validity of...
Create two arguments, one valid and one invalid. Demonstrate with a truth table the validity of each
create two arguments, one valid and one invalid. Demonstrate with a truth table the validity of...
create two arguments, one valid and one invalid. Demonstrate with a truth table the validity of each.
Show your results all planning tools (algorithm, IPO chart, desk checking, pseudocode, flowchart) for an application...
Show your results all planning tools (algorithm, IPO chart, desk checking, pseudocode, flowchart) for an application that allows a user to enter the price of an item and computes 6.25 percent sales tax on the item.
Show your results using all planning tools (algorithm, IPO chart, desk checking, pseudocode, flowchart) for an...
Show your results using all planning tools (algorithm, IPO chart, desk checking, pseudocode, flowchart) for an application that allows a user to enter the number of text messages he or she sent last month and then displays the bill. Messages cost 25 cents each, and 8 percent tax is charged on the total.
Conditions for instruments to be valid include all of the following except: (A) each one of...
Conditions for instruments to be valid include all of the following except: (A) each one of the instrumental variables must be normally distributed. (B) at least one of the instruments must enter the population regression of ?? on the ??s and the ??s. (C) perfect multicollinearity between the predicted endogenous variables and the exogenous variables must be ruled out. (D) each instrument must be uncorrelated with the error term
Assignment Requirements Please complete all parts in a Microsoft Word document. The body of your document...
Assignment Requirements Please complete all parts in a Microsoft Word document. The body of your document should be at least 900 words in length. Quoting should be less than 10% of the entire paper. Paraphrasing is necessary. Students must cite and reference at least 4 credible sources from the Library. Instructions Imagine that you are an administrator for a large hospital. As part of your role within healthcare leadership, you are involved in several committees for the organization. For this...
Follow the steps below to complete your SPSS homework assignment: At the bottom of this document...
Follow the steps below to complete your SPSS homework assignment: At the bottom of this document are 20 questionnaires that were completed by undergraduate students at University XYZ. Open a new SPSS file and save it. Leave the output window open. You will save the output in just a moment. Use the questionnaire questions to correctly define each variable in an SPSS file. Further directions can be found at the following YouTube link: https://www.youtube.com/watch?v=MoKDcPpRa_0 Generate a “file information” output of...
Use the data set attached. Include your SPSS output in this document as part of Step...
Use the data set attached. Include your SPSS output in this document as part of Step 3. Test for the significance of the correlation coefficient at the .05 level using a two-tailed test between hours of studying and grade. Hours of Study Grade 0 80 5 93 8 97 6 100 5 75 3 83 4 98 8 100 6 90 2 78
Please complete a technical analysis for the currency of your choise. In your analysis, please include...
Please complete a technical analysis for the currency of your choise. In your analysis, please include the following tools: MACD (chart and what does it mean) RSI (chart and what does it mean) 50 and 200 days moving averages (chart and what do they mean)
Start an FC-PC Lab Assignment document and save it to your drive. Note: As you complete...
Start an FC-PC Lab Assignment document and save it to your drive. Note: As you complete the below exercises add them to your Assignment document and save it Create the algorithms in both flowchart and pseudocode form for the following two program requirements:   Given is the array prices with 100 elements(prices[100]). The problem consists of two parts:  1. Find the highest price in the array; and  2. Reduce that price by 10% For any three numbers input by the user, output the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT