Question

In: Computer Science

Write a Java method to check whether a string is a valid password. Password rules: A...

Write a Java method to check whether a string is a valid password.

Password rules:
A password must have at least ten characters.
A password consists of only letters and digits.
A password must contain at least two digits.

There are at least SIX functions/methods as the following:

1. menu() – to print the password’s rules.

2. getString() – to get the password from the user.

3. isPassword() – to check either the password is valid based on the given rules. 4

. getChar() - to get the input from the user, either ‘y’ or ‘n’.

5. isLetter() – to check the password to be a letter from ‘A’ to ‘Z’.

6. isNumric() – to check the password to be a number from ‘0’ to ‘9’.

Solutions

Expert Solution

fprintf("1.A password must have at least eight characters.\n") fprintf("2.A password consists of only letters and digits.\n") fprintf("3.A password must contain at least two digits .\n") password=input("Input a password (You are agreeing to the above Terms and conditions.):",'s');

len= length (password);

valid=true;

if len<8 valid=false; else digit_count =0; for i= 1:len ch=password (i);. if ch>='0'&&ch<='9' digit_count=digit_count+

1; elseif(ch<'a' II ch>'z') &&. (ch<'A' II ch>'z') valid=false; end end if digit_count<2 valid =false; end end

if valid printf("password is valid :%S\n", password). else. printf("password is invalid:%S\n", password) end


Related Solutions

Task Intro: Password JAVA. Write a method that checks a password. The rules for the password...
Task Intro: Password JAVA. Write a method that checks a password. The rules for the password are: - The password must be at least 10 characters. - The password can only be numbers and letters. - Password must have at least 3 numbers. Write a test class that tests the checkPassword method. Hint: You can (really should) use method from built-in String class: public boolean matches(String regex) to check that the current string matches a regular expression. For example, if...
2. Write a Java program to read a string (a password)from the user and then   check...
2. Write a Java program to read a string (a password)from the user and then   check that the password conforms to the corporate password policy.   The policy is:   1) the password must be at least 8 characters   2) the password must contain at least two upper case letters   3) the password must contain at least one digit   4) the password cannot begin with a digit   Use a for loop to step through the string.   Output “Password OK” if the password...
•Write a JAVA program to check a given password strength from a user's input. •Create a...
•Write a JAVA program to check a given password strength from a user's input. •Create a method to check the number of characters. It must be more than 8. •Create a method to check the password to have at least one uppercase letter. •Create a method to check the password to have at least one lowercase letter. •Create a method to check the password to have at least one digit. •Create a method to check the password to have at...
Write in Java: Write a method called: public static String[] noIdenticalCombine(String[] array1, String[] array2) { //...
Write in Java: Write a method called: public static String[] noIdenticalCombine(String[] array1, String[] array2) { // instructions: returns an array that contains all the Strings in array1 and array2 but without repetition. order does not matter, but it will return array1's elements and then array2's element that are not in array1. Assume there are no duplicates are in array1 and array2. Could use count which is how many str there are in array2, where !contains(array1, str). May an array of...
(10 marks) Write a function to check whether string s1 is a substring of string s2....
Write a function to check whether string s1 is a substring of string s2. The function returns the first index in s2 if there is a match. Otherwise, return -1. For example, the function should return 2 if s1 is "to" and s2 is "October". If s1 is "andy" and s2 is "candy", then the function should return 1. The function prototype is as follows: int indexOf(const char *s1, const char *s2).
Code in Java Write a recursive method, reverseString, that accepts a String and returns the String...
Code in Java Write a recursive method, reverseString, that accepts a String and returns the String reversed. Write a recursive method, reverseArrayList, that accepts an ArrayList of Strings and returns the ArrayList in reserve order in reserve order of the input ArrayList. Write a main method that asks the user for a series of Strings, until the user enters “Done” and puts them in an ArrayList. Main should make use to reverseArrayList and reverseString to reverse each String in the...
java/netbeans Write a recursive method, reverseString, that accepts a String and returns the String reversed. Write...
java/netbeans Write a recursive method, reverseString, that accepts a String and returns the String reversed. Write a recursive method, reverseArrayList, that accepts an ArrayList of Strings and returns an ArrayList in reserve order of the input ArrayList. Write a main method that asks the user for a series of Strings, until the user enters “Done” and puts them in an ArrayList. Main should make use to reverseArrayList and reverseString to reverse each String in the ArrayList and then reverse the...
Use Python Return a password string constructed with the following rules: (1) If there are only...
Use Python Return a password string constructed with the following rules: (1) If there are only 0 or 1 numeric among 3 parameters, concatenate the string form of all parameters directly. (2) If there are 2 numeric parameters, calculate the sum of 2 numeric values if they are both int, or calculate the product of them and round to 2 decimal places if any of them is float. Finally, append this sum/product to the string parameter. You may assume that...
Please write a Java algorithm solving the following problem: Implement a Java method to check if...
Please write a Java algorithm solving the following problem: Implement a Java method to check if a binary tree is balanced. For this assignment, a balanced tree is defined to be a tree such that the heights of the two subtrees of any node never differ by more than one. 1. First, please create the following two classes supporting the Binary Tree Node and the Binary Tree: public class BinTreeNode<T> { private T key; private Object satelliteData; private BinTreeNode<T> parent;...
Write a Java program that prompts the user to input a string and prints whether it...
Write a Java program that prompts the user to input a string and prints whether it is a palindrome. A palindrome is a string which reads the same backward as forward, such as Madam (disregarding punctuation and the distinction between uppercase and lowercase letters). The program must use the stack data structure. The program must include the following classes: The StackX class (or you can use the Java Stack class). The Palindrome class which must contain a method named palindrome()...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT