Question: Task 6 : The user will be able to give a string as an argument to the method. The method will check if the given

Task 6: The user will be able to give a string as an argument to the method. The method will check if the given string matches the valid password regular expression. The method will return true if the pattern matches, false if any password rule is not met. Complete the method public static boolean checkIfPasswdIsValid to complete this task. See the method comments for more detail.
Task 7: The user will be able to give a string as an argument to the method. The method will match the regular expression pattern for a valid email address and count the number of those valid email addresses that are found in the file. The method will return the number of valid emails found in the string. Complete the method public static int countNumberOfValidEmailAddresses to complete this task. See the method comments for more detail Below is the code I already have /*
* A valid password has the following pattern
*- starts with an uppercase letter
*- ends with a lowercase letter
*- the second to last character is either a number or !
*- the length is at least 8 but no more than 12
*/
public static boolean checkIfPasswdIsValid(String passwd){
return true;
}
/*
* For the purposes of this assignment, assume a valid email address has the following pattern
*- four parts:
*-- Recipient name - made up of uppercase and lowercase letters, digits 0 to 9. Length at least 1, but no more than 32
*-- @ symbol
*-- Domain name - made up of uppercase and lowercase letters, digits 0 to 9. Length at least 1, but no more than 32
*-- Top-level domain - either .com or .net or .edu
*/
public static String countNumberOfValidEmailAddresses(String fileDump){
String emailPattern ="([A-Za-z0-9]{1,32})@([A-Za-z0-9]{1,32}).(com|net|edu)";
Matcher emailMatcher = Pattern.compile(emailPattern).matcher(fileDump);
return emailMatcher.group();
} Below are the strings being read in the driver System.out.println(StringRegExAssignment.checkIfPasswdIsValid("Winter11a")); //true
System.out.println(StringRegExAssignment.checkIfPasswdIsValid("Wint11a")); //false - less than minimum length
System.out.println(StringRegExAssignment.checkIfPasswdIsValid("WinterWonderland11a")); //false - more than max length
System.out.println(StringRegExAssignment.checkIfPasswdIsValid("winter11a")); //false - does not start with uppercase letter
System.out.println(StringRegExAssignment.checkIfPasswdIsValid("Winter11A")); //false - does not end with lowercase letter
System.out.println(StringRegExAssignment.checkIfPasswdIsValid("Winter1_a")); //false - the second to last letter is not a number or !
System.out.println(StringRegExAssignment.checkIfPasswdIsValid("Winter1!a")); //true
System.out.println(StringRegExAssignment.checkIfPasswdIsValid("Metere!d")); //true
System.out.println(StringRegExAssignment.checkIfPasswdIsValid("Secondary!2s")); //true
System.out.println(StringRegExAssignment.checkIfPasswdIsValid("Breaded!x")); //true
System.out.println(StringRegExAssignment.countNumberOfValidEmailAddresses("a@b.comjamaicawhatever jam@jammer.edu")); //2
System.out.println(StringRegExAssignment.countNumberOfValidEmailAddresses("a@b")); //0
System.out.println(StringRegExAssignment.countNumberOfValidEmailAddresses(".net")); //0
System.out.println(StringRegExAssignment.countNumberOfValidEmailAddresses("bb@a.net")); //1
System.out.println(StringRegExAssignment.countNumberOfValidEmailAddresses("forever.and.ever@justdoit.net csciinstructor@georgiasouthern.edu, micromanager@igotnothingbettertodo.com")); //3
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!