Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Big Data 29th British National Conference On Databases Bncod 2013 Oxford Uk July 2013 Proceedings Lncs 7968

Authors: Dan Olteanu ,Georg Gottlob ,Christian Schallhart

2013th Edition

3642394663, 978-3642394669

More Books

Students also viewed these Databases questions

Question

Describe the limbic systems structures and functions.

Answered: 1 week ago