Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem Description Some websites impose certain rules for passwords. Suppose password rules are as follows: 1. A password must have at least eight characters. 2.

image text in transcribed

Problem Description Some websites impose certain rules for passwords. Suppose password rules are as follows: 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. Write a program with class name CheckPassword that prompts the user to entera password and displays Valid password if the rules are followed or Invalid password otherwise. Create three methods (headers given below) to check the three rules. public static boolean AtLeast8(String p) public static boolean LetterOrDigit(String p) public static boolean AtLeast2Digits(String p) 6. Create a method AtLeast2Digits outside the main method with the header provided in the problem description. The password is passed to the string variable For example, method AtLeast8 will return true if there are at least eight characters in the password otherwise it will return false. p in this method. Inside the method do the followings. i) Create an integer variable count and assign zero to it. ii) Create a loop that counts the number of digits in p. The in-built method Character.isDigit(p.charAt(index) returns true if p.charAt(index) is a Here are four sample runs: Sample 1 Enter digit. Increase count by one when a digit is found. your password: My password18 Invalid password iii) If the count is at least 2 then return true inside the loop, otherwise return false outside the loop Sample 2 Enter Invalid password your password: pass18 Sample 3 Enter your password: password Invalid password Sample 4 Enter your password: password18 Valid password You can use the following steps in your code: System.out.print"Enter your password:")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Database Internals A Deep Dive Into How Distributed Data Systems Work

Authors: Alex Petrov

1st Edition

1492040347, 978-1492040347

More Books

Students also viewed these Databases questions

Question

At what point is the tangent to (x) = x 2 + 4x - 1 horizontal?

Answered: 1 week ago