For this question, you will write a Java program that helps validate email addresses. Email addresses...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
For this question, you will write a Java program that helps validate email addresses. Email addresses are often requested as input to websites as a way to validate the identity of the user. To assure that the email provided is actually good, a combination of various validation techniques is required. For the purpose of this question, we will focus on checking whether or not a given string represents a syntactically correct email address. A valid email address consists of a prefix, an '@' symbol, and an email domain. Both the prefix and the domain must be written in acceptable formats. For instance, in the address john.smith@mail.com, "john.smith” is the prefix, and "mail.com" is the domain. Note that, we say that a character is alphanumeric if it is a letter of the alphabet, 'A' to 'Z' or 'a' to 'z', or one of the arabic numerals, '0' to '9'. For instance, 'G' is an alphanumeric character while '&' is not. Acceptable prefix formats. For a prefix to be acceptable it must adhere to the following constraints: • It contains at least one character. • It contains only alphanumeric characters, underscores ('_'), periods ('.'), and dashes ('-'). • An underscore, a period, or a dash must always be followed by one or more alphanumeric characters. • The first and last character must be alphanumeric. Examples of valid prefixes are: "abc-d", "abc.def", "abc", "abc_def". Examples of invalid prefixes are: "abc-", "abc..d", ".abc", "abc#def”. Acceptable domain formats. For a domain to be acceptable it must adhere to the following constraints: • It is made up of two portions separated by a period. • The first portion contains at least one character. • The second portion contains at least two characters. • The first portion contains only alphanumeric characters, periods, and dashes. Moreover, a period or a dash must always be followed by one or more alphanumeric characters. Finally, the first and last character must be alphanumeric. • The second portion contains only letters of the alphabet. Examples of valid domains are: "mail.cc", "mail-archive.com", "mail.org", "mail.mcgill.ca" (here the first portion of the domain is "mail.mcgill", while "ca" is the second portion) Examples of invalid domains are: "mail.c", "mail#archive.com", "mail", "mail..com", ".com", "mail.c9". To complete your task, you need to implement all the methods listed below. All the code for this question must be placed in the file named EmailValidation.java. Note that you are free to write additional methods if they help the design or readability of your code. 1a) Method to check if a character is alphanumeric Write a method isAlphanumeric() that takes as input a character. The method returns true if such character is a letter of the English alphabet (uppercase or lower case) or one of the arabic numerals. The method returns false otherwise. For example: • isAlphanumeric('g') returns true • isAlphanumeric('B') returns true • isAlphanumeric('3') returns true • isAlphanumeric('-') returns false 1b) Methods to check is a character is a valid prefix/domain character Write the following two methods: • A method isValid PrefixChar() that takes as input a character and returns true if the character can be used in the prefix of a valid email address, false otherwise. Note that a valid prefix can contain only alphanumeric characters, dashes, periods, or underscores. For example, isValid PrefixChar('_') returns true, while isValid PrefixChar('&') returns false. • A method isValidDomainChar() that takes as input a character and returns true if the character can be used in the domain (first portion) of a valid email address, false otherwise. Note that a valid first portion of a domain can contain only alphanumeric characters, dashes, or periods. For example, isValidDomainChar('-') returns true, while isValidDomainChar('') returns false. To get full marks, your method must use the isAlphanumeric() method defined above. 1c) Method to check if a String contains exactly one '@' Write a method exactlyOneAt() that takes as input a String representing a possible email address, and returns true if the string contains exactly one '@', false otherwise. For example: • • exactlyOneAt("example@email.com") returns true. exactlyOneAt("b@n@n@s") returns false • exactlyOneAt("@pple") returns true 1d) Method to get the prefix of a possible email address Page 6 Write a method getPrefix() that takes as input a String representing a possible email address. The method returns a String containing the prefix of the possible email address. In this method, you can assume that the String received as input contains exactly one '@'. For example: • getPrefix("example@email.com") returns "example". ⚫ getPrefix("cats @nd dogs") returns "cats". • getPrefix("@pple") returns "". 1e) Method to get the domain of a possible email address 1e) Method to get the domain of a possible email address Write a method getDomain() that takes as input a String representing a possible email address. The method returns a String containing the domain of the possible email address. In this method, you can assume that the String received as input contains exactly one '@'. For example: • getDomain("example@email.com") returns "email.com". • getDomain("cats @nd dogs") returns "nd dogs". • getDomain("@pple") returns "pple". 1f) Methods to check if the prefix and the domain are valid Write the following two methods: ⚫ isValidPrefix() takes a String as input representing the prefix of a possible email address. The method returns true if the input adhere to all the constraints listed in the above paragraph titled "Acceptable prefix formats", false otherwise. ⚫ isValidDomain() takes a String as input representing the domain of a possible email address. The method returns true if the input adhere to all the constraints listed in the above paragraph titled "Acceptable domain formats", false otherwise. Examples: ⚫ isValidPrefix("abc_def") returns true. ⚫ isValid Prefix("mail.cc") returns true. ⚫ isValid Prefix("abc..d") returns false. ⚫ isValid Prefix("abc#d") returns false. ⚫ isValidDomain("mail.cc") returns true. ⚫ isValidDomain ("abc-def.ghi") returns true. ⚫ isValidDomain ("abc..d") returns false. ⚫ isValidDomain(".com") returns false. ⚫ isValidDomain(".com.com") returns false. To get full marks, your method must use at least isValid PrefixChar() and isValidDomainChar(). 1g) Methods to check if a string is a valid email address Write the method isValid Email() which takes as input a String and returns true if the string is a valid email address, false otherwise. To get full marks, your method must use all the methods you have written up to now (either directly or indirectly). For example: ⚫ isValidEmail("abc..def@mail.com") returns false. ⚫ isValidEmail("abc#def@mail.com") returns false. ⚫ isValidEmail("abc.def@mail") returns false. ⚫ isValidEmail("abc.def@mail..com") returns false. ⚫ isValidEmail("abc_d@mail.com") returns true. ⚫ isValidEmail("abc.def@mail.com") returns true. ⚫ isValidEmail("abc@mail.com") returns true. ⚫ isValidEmail("abc.def@mail-archive.com") returns true. For this question, you will write a Java program that helps validate email addresses. Email addresses are often requested as input to websites as a way to validate the identity of the user. To assure that the email provided is actually good, a combination of various validation techniques is required. For the purpose of this question, we will focus on checking whether or not a given string represents a syntactically correct email address. A valid email address consists of a prefix, an '@' symbol, and an email domain. Both the prefix and the domain must be written in acceptable formats. For instance, in the address john.smith@mail.com, "john.smith” is the prefix, and "mail.com" is the domain. Note that, we say that a character is alphanumeric if it is a letter of the alphabet, 'A' to 'Z' or 'a' to 'z', or one of the arabic numerals, '0' to '9'. For instance, 'G' is an alphanumeric character while '&' is not. Acceptable prefix formats. For a prefix to be acceptable it must adhere to the following constraints: • It contains at least one character. • It contains only alphanumeric characters, underscores ('_'), periods ('.'), and dashes ('-'). • An underscore, a period, or a dash must always be followed by one or more alphanumeric characters. • The first and last character must be alphanumeric. Examples of valid prefixes are: "abc-d", "abc.def", "abc", "abc_def". Examples of invalid prefixes are: "abc-", "abc..d", ".abc", "abc#def”. Acceptable domain formats. For a domain to be acceptable it must adhere to the following constraints: • It is made up of two portions separated by a period. • The first portion contains at least one character. • The second portion contains at least two characters. • The first portion contains only alphanumeric characters, periods, and dashes. Moreover, a period or a dash must always be followed by one or more alphanumeric characters. Finally, the first and last character must be alphanumeric. • The second portion contains only letters of the alphabet. Examples of valid domains are: "mail.cc", "mail-archive.com", "mail.org", "mail.mcgill.ca" (here the first portion of the domain is "mail.mcgill", while "ca" is the second portion) Examples of invalid domains are: "mail.c", "mail#archive.com", "mail", "mail..com", ".com", "mail.c9". To complete your task, you need to implement all the methods listed below. All the code for this question must be placed in the file named EmailValidation.java. Note that you are free to write additional methods if they help the design or readability of your code. 1a) Method to check if a character is alphanumeric Write a method isAlphanumeric() that takes as input a character. The method returns true if such character is a letter of the English alphabet (uppercase or lower case) or one of the arabic numerals. The method returns false otherwise. For example: • isAlphanumeric('g') returns true • isAlphanumeric('B') returns true • isAlphanumeric('3') returns true • isAlphanumeric('-') returns false 1b) Methods to check is a character is a valid prefix/domain character Write the following two methods: • A method isValid PrefixChar() that takes as input a character and returns true if the character can be used in the prefix of a valid email address, false otherwise. Note that a valid prefix can contain only alphanumeric characters, dashes, periods, or underscores. For example, isValid PrefixChar('_') returns true, while isValid PrefixChar('&') returns false. • A method isValidDomainChar() that takes as input a character and returns true if the character can be used in the domain (first portion) of a valid email address, false otherwise. Note that a valid first portion of a domain can contain only alphanumeric characters, dashes, or periods. For example, isValidDomainChar('-') returns true, while isValidDomainChar('') returns false. To get full marks, your method must use the isAlphanumeric() method defined above. 1c) Method to check if a String contains exactly one '@' Write a method exactlyOneAt() that takes as input a String representing a possible email address, and returns true if the string contains exactly one '@', false otherwise. For example: • • exactlyOneAt("example@email.com") returns true. exactlyOneAt("b@n@n@s") returns false • exactlyOneAt("@pple") returns true 1d) Method to get the prefix of a possible email address Page 6 Write a method getPrefix() that takes as input a String representing a possible email address. The method returns a String containing the prefix of the possible email address. In this method, you can assume that the String received as input contains exactly one '@'. For example: • getPrefix("example@email.com") returns "example". ⚫ getPrefix("cats @nd dogs") returns "cats". • getPrefix("@pple") returns "". 1e) Method to get the domain of a possible email address 1e) Method to get the domain of a possible email address Write a method getDomain() that takes as input a String representing a possible email address. The method returns a String containing the domain of the possible email address. In this method, you can assume that the String received as input contains exactly one '@'. For example: • getDomain("example@email.com") returns "email.com". • getDomain("cats @nd dogs") returns "nd dogs". • getDomain("@pple") returns "pple". 1f) Methods to check if the prefix and the domain are valid Write the following two methods: ⚫ isValidPrefix() takes a String as input representing the prefix of a possible email address. The method returns true if the input adhere to all the constraints listed in the above paragraph titled "Acceptable prefix formats", false otherwise. ⚫ isValidDomain() takes a String as input representing the domain of a possible email address. The method returns true if the input adhere to all the constraints listed in the above paragraph titled "Acceptable domain formats", false otherwise. Examples: ⚫ isValidPrefix("abc_def") returns true. ⚫ isValid Prefix("mail.cc") returns true. ⚫ isValid Prefix("abc..d") returns false. ⚫ isValid Prefix("abc#d") returns false. ⚫ isValidDomain("mail.cc") returns true. ⚫ isValidDomain ("abc-def.ghi") returns true. ⚫ isValidDomain ("abc..d") returns false. ⚫ isValidDomain(".com") returns false. ⚫ isValidDomain(".com.com") returns false. To get full marks, your method must use at least isValid PrefixChar() and isValidDomainChar(). 1g) Methods to check if a string is a valid email address Write the method isValid Email() which takes as input a String and returns true if the string is a valid email address, false otherwise. To get full marks, your method must use all the methods you have written up to now (either directly or indirectly). For example: ⚫ isValidEmail("abc..def@mail.com") returns false. ⚫ isValidEmail("abc#def@mail.com") returns false. ⚫ isValidEmail("abc.def@mail") returns false. ⚫ isValidEmail("abc.def@mail..com") returns false. ⚫ isValidEmail("abc_d@mail.com") returns true. ⚫ isValidEmail("abc.def@mail.com") returns true. ⚫ isValidEmail("abc@mail.com") returns true. ⚫ isValidEmail("abc.def@mail-archive.com") returns true.
Expert Answer:
Answer rating: 100% (QA)
Table of contents Typed code Code screenshot Output Typed code EmailValidationjava import javalang public class EmailValidation method to check if a character is alphanumeric public boolean isAlphanum... View the full answer
Related Book For
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch
Posted Date:
Students also viewed these programming questions
-
In this question you will be asked to reflect on a project you have been involved in or observed, in which a design evolved, or could have evolved, through applying a theory of user behaviour. You...
-
Explain the Mechanism & routes of administration of SEDDS (Self emulsifying drug delivery system).
-
Raynham's Radiology Center (RRC) performs X-rays, ultrasounds, computer tomography (CT) scans, and magnetic resonance imaging (MRI). RRC has developed a reputation as a top radiology center in the...
-
Evaluate the following integrals. |vs V9 - 4x dx
-
Barbara Vigil, Chief Justice, New Mexico Supreme Court Ken Badilla bought a pair of Brahma brand work boots from Wal-Mart on October 19, 2003. The boots packaging had these express descriptions: iron...
-
The following information pertains to Miner Video Company. 1. Cash balance per bank, July 31, $7,263. 2. July bank service charge not recorded by the depositor $28. 3. Cash balance per books, July...
-
Stage duration (hours) for immatures of 2 species of blow fly when reared at several temperatures; e.g., "time to complete" the stage. The threshold temperature for all species is 10C.--------1. What...
-
Warden Repairs showed the following adjusted account balances on October 31, 2023. Prepare and post the closing entries. Assets 250 Withdrawals 20 Income Summary Liabilities 110 Revenue 100 Capital...
-
The beam is connected to a fixed support at A. The beam has an abrupt change in cross section at point B. Sections AB and BC both have solid circular cross sections of diameter AB and BC,...
-
Consider a stock that is expected to pay a dividend of $2.76 one year from now. The dividend is expected to grow at a constant rate of 1.7% per year forever. Firms in the same industry provide an...
-
The current model Boeing 737 has a capacity of 189 passengers.Suppose Delta Airlines uses this equipment for its Atlanta toHouston flights. The distribution of the number of seats sold forthe Atlanta...
-
What would some objectives be for verbal outburst and pushing materials on the floor?
-
If I am creating a 5-digit number combination, how many combinations will be created if the first digit is an odd number and the last digit are either 0,7 or 9 or the 3 middle digits are all prime...
-
Calculate the effective yield of a monthly-payment FRM of $500,000, 3.5%, 30 years with a 2 up-front discount points, assuming the loan is paid off at the end of the fifth year?
-
Find the minimum sample size n needed to estimate u for the given values of c, a, and E. c= 0.90, a = 6.4, and E= 1 Assume that a preliminary sample has at least 30 members. n = (Round up to the...
-
For what reason might an exporter use standard international trade documentation (letter of credit, draft, order bill of lading) on an intrafirm export to its parent or sister subsidiary?
-
Write a JavaFx application that draws a bulls-eye pattern. The center should be a filled-in blue circle with a diameter of 100 pixels. The center circle should be surrounded by five rings that...
-
Write a JavaFx application to draw the five interlocking rings that are the symbol of the Olympics. The color of the rings, from left to right, is blue, yellow, black, green, and red.
-
Repeat the previous programming project, but read the input data from a file and send the output to another file. If you have covered binary files, use binary files; otherwise, use text files. Read...
-
In a diploid species, complete nondisjunction during meiosis I may produce a viable cell that is a. trisomic. b. haploid. c. diploid. d. triploid.
-
Which of the following statements is correct? a. If a deletion and a duplication are the same size, the deletion is more likely to be harmful. b. If a deletion and a duplication are the same size,...
-
Which of the following is a type of plasmid? a. F factor (fertility factor) b. R factor (resistance plasmid) c. Virulence plasmids d. All of the above are types of plasmids.
Study smarter with the SolutionInn App