Document-File-Email exercise

•Define a class named Document that contains an instance variable text of type String. Define a toString() method to return the value of text. Define a mutator method to set the value of the string.

•Next, define a class Email that derives/extends the class Document. Email will have three instance variable Sender, Recipient and Title. Implement appropriate accessor and mutator methods for these variables. The body of the Email will be stored in the inherited variable text. Redefine the toString method to concatenate all the fields of the Email.
  • Write a driver class containing the main method. Create instance of Email with the following info: sender: yourname@ucalgary.ca receiver: csus@ucalgary.ca title: membership body: Hi I am yourname. How can I be a part of Computer Science Undergraduate Society? Thanks.
•Similarly, define another class File that is derived from Document and includes an instance variable for pathname. The textual contents of the file should be stored in the inherited variable text. Redefine the toString method to read the file stored in the pathname and return its contents. (Resources for reading files Slides)
•Finally, create several sample objects of type Email and File in your main method. Test your objects by passing them to the following subroutine that returns true if the object contains the specified keyword in the text property.

public static boolean containsKeyWord(Document docObject, String keyword){

if(docObject.toString().indexOf(keyword,0)>=0)

return true;

else

return false;

}