Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

import java.util.regex.Pattern; import javax.swing.JOptionPane; public class Val

ID: 3542460 • Letter: I

Question

import java.util.regex.Pattern;

import javax.swing.JOptionPane;



public class ValidPassword {


    public static void main(String[] args) {

        

        String password = JOptionPane.showInputDialog("Enter your password ");


         boolean lessOrMoreCharacters = false, digit = false, spaces = false;


         if (password.length() > 10 || password.length() < 6) {


          lessOrMoreCharacters = true;


        lessOrMoreCharacters = true;


          }


        if (!Pattern.compile("[0-9]").matcher(password).find()) {


           digit = true;


        }


       if (Pattern.compile("\s").matcher(password).find()) {


        spaces = true;


       }

        

        if (lessOrMoreCharacters && digit && spaces) {

            JOptionPane


          .showMessageDialog(


             null,


            "Invalid password. Errors you committed. Password lenth should be in the range 6 to 10 characters. Password should have at least one digit Password should not have any space. ");

             } // end of if


         else if (lessOrMoreCharacters && digit) {

            JOptionPane


            .showMessageDialog(


            null,


                   "Invalid password. Errors you committed. Password lenth should be in the range 6 to 10 characters. Password should have at least one digit. ");

             } // end if 1st if else


        else if (lessOrMoreCharacters && spaces) {

            JOptionPane


             .showMessageDialog(


            null,


            "Invalid password. Errors you committed. Password lenth should be in the range 6 to 10 characters. Password should not have any space. ");

        } // end of 2nd if else


       else if (spaces && digit) {

            JOptionPane


           .showMessageDialog(


             null,


           "Invalid password. Errors you committed. Password should have at least one digit. Password should not have any space. ");

        } // end of 3rd if else


      else if (spaces) {

            JOptionPane


            .showMessageDialog(


            null,


            "Invalid password. Errors you committed. Password should not have any space. ");

        } // end of 4th if else


        else if (digit) {

            JOptionPane


            .showMessageDialog(


          null,


       "Invalid password. Errors you committed. Password should have at least one digit. ");

        } // end of 5th if else


      else if (lessOrMoreCharacters) {

            JOptionPane


                .showMessageDialog(


                    null,


                   "Invalid password. Errors you committed. Password lenth should be in the range 6 to 10 characters. ");

        } // end of 6th if else


              else {

            JOptionPane.showMessageDialog(null, " It is a valid password ");

        }


        

        

        

    } // end of main

} // end of class

Explanation / Answer