1 import java.util.*;2 import java.util.Date;3 public class DocumentASteele4 {5 }67 class Document8 {9 private String content;10 public Document(String content) //Constructor11 {12 this.content = content; //initiliaze variable content in this parameter13 }14 public String getContent() //Method that returns instance variable content15 {16 return content;17 }18 public void setContent(String newContent) //Method that changes instance variable content to new content19 {20 this.content = newContent;21 }22 public String toString() //Method that creates a String representing an object of Document and then returns it.23 {24 return content;25 }26 public int getContentLength() //Method that returns the lenght of the String27 {28 return this.content.length(); //Gives the number of the letters in the variable content.29 }30 public boolean contains(String keyword) //Method containing keyword31 {32 if(this.content.contains(keyword))33 {34 return true; //True if keyword is found35 }36 else37 {38 return false; //False if keyword is not found39 }40 }41 public boolean equals(Document other) //Method that compares two object that's type Document42 {43 if(this.content.equalsIgnoreCase(other.content))44 {45 return true; //True if two documents are same46 }47 else48 {49 return false; //False if two documents are different50 }51 }52 }5354 class Email extends Document55 {56 //Below are the variables for Email class57 private String sender;58 private String recipient;59 private Date date; //date of the email using the Date util package60 private String subject; //email subject61 private String cc; //list of people to be included on the email62 boolean isSent; //specifies if email has been sent6364 //CONSTRUCTOR initializing instance variables and in given parameters65 public Email(String text, String sender, String recipient, String subject, String cc) //Constructor with the variables listed above66 {67 super(content);68 this.Sender = sender;69 this.Recipient = recipient;70 this.Subject = subject;71 this.CC = cc;72 this.Date = new Date();73 }74 public void send() //Method sets the instance variable isSent to true meaning that this email has been sent.75 {76 this.isSent = true;77 }78 public String forward(String recipient, String cc)79 {80 return recipient; //unsure of this code81 return cc; //unsure of this code82 }83 //GETTER METHODS84 public boolean getSent() //returns the instance variable isSent85 {86 return isSent;87 }88 public String getSender() //returns the instance variable sender89 {90 return this.Sender;91 }92 public String getRecipient() //returns the instance variables recipient93 {94 return this.Recipient;95 }96 public String getSubject() //returns the instance variable subject97 {98 return this.Subject;99 }100 public String getCC() //returns the instance variable cc101 {102 return this.CC;103 }104 public Date getDate() //returns the date instance variable105 {106 return this.Date;107 }108 //SETTER METHODS109 public void setSender(String s)110 {111 if(isSent == false) //checking instance variable isSent112 {113 sender = s; //if false then email is not sent and sender can still be modified114 }115 else //or else it's true and sender cannot be modified116 {117 System.out.println("This email has been sent and sender cannot be modified.");118 }119 }120 public String setRecipient(String r)121 {122 if(isSent == false) //checking instance variable isSent123 {124 recipient = r; //if false then email is not sent and recipient can still be modified125 }126 else //or else it's true and recipient cannot be modified127 {128 System.out.println("This email has been sent and recipient cannot be modified.");129 }130 }131 public void setSubject(String s)132 {133 if(isSent == false) //checking instance variable isSent134 {135 subject = s; //if false then email is not sent and subject can still be modified136 }137 else //or else it's true and subject cannot be modified138 {139 System.out.println("This email has been sent and subject cannot be modified.");140 }141 }142 public void setCC(String c)143 {144 if(isSent == false) //checking instance variable isSent145 {146 cc = c; //if false then email is not sent and cc can still be modified147 }148 else //or else it's true and recipient cannot be modified149 {150 System.out.println("This email has been sent and CC cannot be modified.");151 }152 }153 public String toString()154 {155 return156 "EMAIL APPLICATION \n" +157 "Sender: " + sender + "\n" +158 "Recipient: " + recipient + "\n" +159 "Date: " + Date + "\n" +160 "Subject: " + subject + "\n" +161 "Message Content: " + super.toString(); //calling the toString method from the Document class162 }163 public void modifyContent(String s)164 {165 if(isSent == false) //checking instance variable isSent166 {167 super.setContent(s); //if false then email is not sent and content can still be modified168 }169 else //or else it's true and content cannot be modified170 {171 System.out.println("This email has been sent and content cannot be modified.");172 }173 }174 public Email forward(String rec, String sender, String cc)175 {176 Email fwd = new Email(this.getText(), sender, rec, this.subject, cc);177 fwd.Date = new Date();178 fwd.isSent = true;179 return fwd;180 }181 }182183 class EmailDriver184 {185 // public Email(String text, String sender,String recipiant, String subject, String cc)186 public static void main(String[] args)187 {188 //creating an Email object189 Email e1 = new Email("Hello everyone, we will have a meeting tomorrow at 10", "Gita Faroughi","Alex","Meeting","");190191 //sending the email192 e1.send();193194 //disply the details about the email195 System.out.println(e1);196 System.out.println("\n\n");197198 //searching the email for the email for the word tomorrow199 boolean b = e1.contains("tmorrow");200 if(b)201 System.out.println("The word tomorrow was found in the email");202 else203 System.out.println("The word tomorrow was found in the email");204205206 //displaying just the content(text) of the email207 System.out.println("\nThe content of this email is: " + e1.getText());208 System.out.println();209 //modifying the content of the email210 e1.modifyContent("bye");211212 //changing the recipient of the e1 email213 e1.setRecipient("[email protected],[email protected]");214 System.out.println();215216 //forwarding the email217 Email forward = e1.forward("Alex", "Gita" ,"Maria");218 System.out.println();219220 //printing the forwarded email221 System.out.println("forwarded message\n"+ forward);222 System.out.println();223224 //display the length of the text in the email225 System.out.println("The number of the letters in the email is: " + e1.getDocumentLength());226227 //***********************************************************************228 //your turn, refer to the provided documnet on the codes you need to write229230 }231 }
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here