Specifications: Class Class From To Constructor
Specifications: Class Class From To Constructor
Specifications: Class Class From To Constructor
Your task here is to implement a Java code based on the following specifications.
Note that your code should match the specifications in a precise manner. Consider
default visibility of classes, data fields and methods unless mentioned otherwise.
Specifications:
class definitions:
class Header:
Variables:
String from
String to
Implement a parameterized constructor to initialize all
the instance variables.
class Email:
Variables:
Header header
String body
String greetings
Implement a parameterized constructor to initialize all
the instance variables.
class EmailOperations:
Methods:
emailVerify(Email e): Use regular expression to
verify if the two email-ids in the Header class is valid or not.[Return
type explained in Task part].
Return type:int
Visibility: public
Class Variables:
class Header: It contains two email id 'from' and 'to'. 'from' signifies the
sender's email address and 'to' signifies receiver's email address.
class Email: This class contains three parts: first Header header which has
two email address from and to,the second body which contains the message
to send and third greetings which contains greetings such as "Regards",
"Thank you", etc.
<Email(obj)>.<Email(variable)>.<Header(variable)>
Example to access "from" address from the Email object e we use : e.header.from;
Tasks:
1. emailVerify (Email e)
2. bodyEncryption (Email e)
3. greetingMessage (Email e)
Method Description:
1. emailVerify(Email e):
In this method you have to use regex to check if the email-address to and
from in Header class is valid or not. Validation is based on:
Email address should start with alphabets(capital/small) or _(underscore).
Email address should have only one @ followed by alphabets.
Email address should end with .(dot) followed by alphabets.
e.g: amit@doselect.com, _ami@doselect.in are valid addresses, but
1ami@dos.com, amit@doselect are invalid addresses.
Return 2 if the both email addresses are valid return 1 if one is valid, and 0 if
both are invalid.
2. bodyEncryption(Email e):
In this method, you have to use Caesar cipher(shift of 3) to encrypt the body
part of the Email return the encrypted string.
Caesar shift, is one of the simplest and most widely known encryption
techniques. It is a type of substitution cipher in which each letter in the
plaintext is replaced by a letter some fixed number of positions down the
alphabet. Here the number of shift is 3.
e.g: str = "Hi There Hows you", after encryption becomes "Kl Wkhuh Krzv brx".
H get converted to K that is a shift of 3 alphabets ahead.
Letters which are capital should be capital and small should be small in
Encrypted message. Take care of the spaces.
3. greetingMessage(Email e):
In this method, you have to return a concatenated string which contains the
greetings variable from Email class and Name of the person who is sending
the mail(from variable in the Header class).
The name part should not contain anything which is after @ in the email id.
e.g: if greetings = "Regards" and from = "Amit@doselect.com" then you have
to return the message "Regards Amit"
Important:
To check your program you have to use the main() function(in Source class)
given in the stub. You can make suitable function calls and use RUN
CODE button to check your main() function output.