Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Specifications: Class Class From To Constructor

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

CODE 4

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

bodyEncryption(Email e): Use Ceasar cipher(Shift-


3) to encrypt the body of the email.[To know more refer the Task part] 
Return type:String
Visibility: public

greetingMessage(Email e): In this method you have


to return a greeting messgae. The greet part should be taken from
greetings variable and signature(name) should be taken from Header's
'from' email address.[To know more refer the Task part] 
Return type:String
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.

To access a variable in Header class through Email object we use:

<Email(obj)>.<Email(variable)>.<Header(variable)>

Example to access "from" address from the Email object e we use : e.header.from;

Tasks:

 Implement the two classes Email and Header class according to the


specifications.
 Implement the three methods in the EmailOperations class:

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.

You might also like