Import java.util.Scanner;/** Method validate() takes a

import java.util.Scanner;
/*
* Method validate() takes a password string and determines if it is a valid password
* Valid passwords are at least 8 characters in length and contain at least: one upper case letter,
* one lower case character, one digit, and one of 3 special characters from the set ‘!’ ‘$’ ‘#’
*/
public class QB4
{
 /*
  * Validate a password string. Returns true if the string is at least 8 characters in length and
  * contains at least: one upper case character, one lower case character, one digit and contains one special
  * character from the set of 3 special characters ‘!’ ‘$’ ‘#’
  * returns false otherwise
  *
  */
public static boolean validate(String password)
{
 //———–Start below here. To do: approximate lines of code = 17
 // Fill in the method. Hint: make use of String method charAt(), class Character static methods:
  // isLowerCase(), isUpperCase(), isDigit()
 
 
 //—————–End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}

public static void main(String[] args)
{
String password = “aBc123xyz!”;

 Scanner in = new Scanner(password);
 if (validate(in.next()))
 System.out.println(“ok”);
 else
 System.out.println(“Invalid Password”);
 System.out.println(“Expected:ok”);
 
 password = “aBcxyz”;
 in = new Scanner(password);
 if (validate(in.next()))
 System.out.println(“ok”);
 else
 System.out.println(“Invalid Password”);
 System.out.println(“Expected:Invalid Password”);
 
 password = “hello$”;
 in = new Scanner(password);
 if (validate(in.next()))
 System.out.println(“ok”);
 else
 System.out.println(“Invalid Password”);
 System.out.println(“Expected:Invalid Password”);
 
 password = “Hello123#”;
 in = new Scanner(password);
 if (validate(in.next()))
 System.out.println(“ok”);
 else
 System.out.println(“Invalid Password”);
 System.out.println(“Expected:ok”);

}
}

Include screenshots of the output. 

 

Leave a Comment

Your email address will not be published. Required fields are marked *

GradeEssays.com
We are GradeEssays.com, the best college essay writing service. We offer educational and research assistance to assist our customers in managing their academic work. At GradeEssays.com, we promise quality and 100% original essays written from scratch.
Contact Us

Enjoy 24/7 customer support for any queries or concerns you have.

Phone: +1 213 3772458

Email: support@gradeessays.com

© 2024 - GradeEssays.com. All rights reserved.

WE HAVE A GIFT FOR YOU!

15% OFF 🎁

Get 15% OFF on your order with us

Scroll to Top