Please someone hlep me, based on the java code given how can i make the change to program run like the example given. InvalidPasswordException.java public class InvalidPasswordException extends Exception{     public InvalidPasswordException (String errMsg){         super(errMsg);

Programming with Microsoft Visual Basic 2017
8th Edition
ISBN:9781337102124
Author:Diane Zak
Publisher:Diane Zak
Chapter2: Planning Applications And Designing Interfaces
Section: Chapter Questions
Problem 1MQ3
icon
Related questions
Question

Q1 Please someone hlep me, based on the java code given how can i make the change to program run like the example given.

InvalidPasswordException.java

public class InvalidPasswordException extends Exception{
    public InvalidPasswordException (String errMsg){
        super(errMsg);
    }
    
}

 

Password.java

public class Password  {
private String passwordstr;
    

  public Password (String passwordstr) throws InvalidPasswordException {
          if (passwordstr== null ||passwordstr.equals("")) {
          throw new InvalidPasswordException("Invalid password: password cannot be null or an empty string.");
      } else {
                int countDigits=0;

                int countLetters=0;
                
    for (int i=0; i<passwordstr.length();++i)
              
{
              char ch = passwordstr.charAt(i);
              if (Character.isDigit(ch))
                  
                            countDigits++;

              else if (Character.isLetter(ch)) 
                  
                            countLetters++;

          }
                       
                            int countAlphaNumeric =countDigits + countLetters;
          String errMsg = "";
          if (countDigits == 0)
          errMsg += "Your password should have at least 1 digit.\n";


                
          if (countLetters==0)    
                errMsg += "Your password should have at least 1 digit.\n";


                
                       if(countAlphaNumeric <7)
          errMsg += "Your password should have at least 7 alpha-numeric character.\n";      

    
          if (!errMsg.equals(""))
              throw new InvalidPasswordException(errMsg);
      }
                this.passwordstr=passwordstr;
    
  }
}

 

import javax.swing.*;  
class TextFieldExample  
{  
public static void main(String args[])  
    {  
    JFrame f= new JFrame("TextField Example");  
    JTextField t1,t2;  
    t1=new JTextField("Enter your password");  
    t1.setBounds(50,100, 200,30);  
     
  
    f.add(t1);  
 
    JButton b=new JButton("Click Here");  
    b.setBounds(50,100,95,30);  
    f.add(b); 
 
    f.setSize(400,400);  
    f.setLayout(null);  
    f.setVisible(true);  
    }  
    }  
Set Password
Enter your password
Submit
Invalid password: password cannot be null or an empty string
Set Password
O X
Enter your password
Submit
Your password should have at least 1 letter.
Transcribed Image Text:Set Password Enter your password Submit Invalid password: password cannot be null or an empty string Set Password O X Enter your password Submit Your password should have at least 1 letter.
Set Password
Enter your password
Submit
Your password should have at least 1 digit.
Your password should have at least 7 alpha-numeric
characters.
Set Password
Enter your password
Submit
Congratulations! Your password is valid.
Transcribed Image Text:Set Password Enter your password Submit Your password should have at least 1 digit. Your password should have at least 7 alpha-numeric characters. Set Password Enter your password Submit Congratulations! Your password is valid.
Expert Solution
steps

Step by step

Solved in 3 steps with 6 images

Blurred answer
Knowledge Booster
Exception Handling Keywords
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning