Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA Write a program that validates a password using the following conditions: A password must consist of only letters and digits A password must have

JAVA

Write a program that validates a password using the following conditions:

A password must consist of only letters and digits

A password must have at least eight characters

A password must contain at least two digits

Your program should include methods with the following headers:

// Returns true if s is made up of only letters and digits, false otherwise public static boolean isOnlyLettersDigits(String s) // Returns true if s is at least eight characters long, false otherwise public static boolean isProperLength(String s) // Returns true if s contains at least two digits, false otherwise public static boolean isMinTwoDigits(String s) 

Hints:

s.charAt(i) returns the character located at index i

s.length returns the length of the string s

Character.isLetter(s.charAt(i)) returns true if the character at index i is a letter

Character.isDigit(s.charAt(i)) returns true if the character at index i is a digit

Sample input:

J123akes 

Sample output for above input:

J123akes is a valid password 

Sample input:

J123ake$ 

Sample output for above input:

J123ake$ is an invalid password

image text in transcribed

Load default template... 1 public class PasswordValidator { 2 public static void main(String[] args) Include code to read in a string. You should call the appropriate methods to validate the password and then output either "Valid Password" or "Invalid Password 9 10 public static boolean ?sOnlyLettersDigts(string s) { Verify that every character in the string consists of either a letter or a digit If so, return true. If not, return false 12 13 14 15 public static boolean isProperLength(String s) 16 17 18 19 20 public static boolean isMinTwoDigits (String s) 21 / Verify that the string is at least eight characters long If so, return true. If not, return false Verify that the string includes at least two digits If so, return true. If not, return false Hint: Use a for loop to examine each character and if a digit is found, increment a counter 23 24 25 26 27 28

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions