Class GmailAddresses
An email address looks like username@domain. Gmail has a few interesting tricks you can use on your email addresses. First, you can add a . character anywhere in the username portion of the address and it won't matter. For example bob.smith@gmail.com, b.obsmi.th@gmail.com and .bob..smith.@gmail.com will all be sent to bobsmith@gmail.com. Second, you can append extra words onto the end of the user name using a + sign. For example, bobsmith+home@gmail.com will also be sent to bobsmith@gmail.com. Everything between the + and the @ are ignored.
In gmail emails are received with the dots and pluses intact so you can see what original address was used.
For this assignment, you ask the user for gmail addresses and you resolve it to the actual user's gmail address. You will need to write three different methods, as defined in this documentation, for doing so and output the results.
Each method's documentation lists the methods of the String class you are allowed to use, do not use any others. Nor should you use the StringBuffer, StringBuilder, or similar work-around to avoid using Strings. Look at the documentation for String at https://docs.oracle.com/javase/8/docs/api/java/lang/String.html. Note that some methods, like indexOf, are overloaded with different parameter lists.
Use well-designed loops and loop conditions. Do not use while(true), break, or continue to execute your loop. They have their place, but that place is not here.
Do not use arrays even if you are familiar with them.
Sample Execution
Enter a gmail address:
bob.smith@gmail.com
bob.smith@gmail.com resolves to bobsmith@gmail.com.
Enter a gmail address:
bob.smith+home@gmail.com
bob.smith+home@gmail.com resolves to bobsmith@gmail.com.
Enter a gmail address:
bob.smith
bob.smith is not a correct address.
Enter a gmail address:
+bob.smith@gmail.com
+bob.smith@gmail.com resolves to @gmail.com which is an incorrect email address.
Enter a gmail address:
done
2 out of 4 addresses were completely correct.
Testing
Create a file called test.txt containing the input for you program, and set up eclipse to use your file as input to this program as we did in class (reminder below). Be sure to check various correct and failure cases using the input file. Copy the output from your program to a file called output.txt. Submit both you text files with your assignment.Reading input from a file in eclipse
- Open the "Run Configurations..." dialog box. You can do so through the Run menu, or the drop-down next to the Run button.
- Select the Common tab.
- Check the Input File checkbox.
- Use the Workspace... or FileSystem... button to find and select your input file.
- Be sure your file ends with a blank line (type return/enter after the word done).
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringRemove the '.' characters from the username portion of the email address given by the address parameter.static StringRemove everything from the first + to the @ symbol in the email address provided in the address parameter.static booleanisCorrectAddress(String address) Determine if the email address is correct.static voidAsk the user to enter gmail addresses, and print out the resolved address until the user enters the word, "done".
-
Method Details
-
main
Ask the user to enter gmail addresses, and print out the resolved address until the user enters the word, "done". Use the fixDots and fixPlus methods in the class to resolve each address. If the input is not a proper email address, print out an error message. If the resolved address is not a proper email address, print it and an error message. The sentinel value, "done" can be upper or lower case, or a combination.
- Parameters:
args- Command Line Arguments.
-
isCorrectAddress
Determine if the email address is correct. A correct email address will be of the form username@domain. It should contain exactly one @ symbol, and neither username nor domain should be empty (contain no characters).
You may use the indexOf and length methods of String for this method.
- Parameters:
address- The address to be checked.- Returns:
- true if address is correctly formed, false otherwise.
-
fixDots
Remove the '.' characters from the username portion of the email address given by the address parameter.
You may use the indexOf and substring methods of String for this method.
- Parameters:
address- The address to be processed. It should be the form username@domain.- Returns:
- A String containing the processed address.
-
fixPlus
Remove everything from the first + to the @ symbol in the email address provided in the address parameter.
You may use the charAt and length methods of String for this method.
- Parameters:
address- The address to be processed. It should be the form username@domain.- Returns:
- A String containing the processed address.
-