1 import java.util.*; 2 import java.util.Date; 3 public class DocumentASteele 4 { 5 } 6 7 class Document 8 { 9 private String content; 10 public Document(String content) //Constructor 11 {...


1 import java.util.*;

2 import java.util.Date;

3 public class DocumentASteele

4 {

5 }

6

7 class Document

8 {

9 private String content;
10 public Document(String content) //Constructor
11 {
12 this.content = content; //initiliaze variable content in this parameter
13 }
14 public String getContent() //Method that returns instance variable content
15 {
16 return content;
17 }
18 public void setContent(String newContent) //Method that changes instance variable content to new content
19 {
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 String
27 {
28 return this.content.length(); //Gives the number of the letters in the variable content.
29 }
30 public boolean contains(String keyword) //Method containing keyword
31 {
32 if(this.content.contains(keyword))
33 {
34 return true; //True if keyword is found
35 }
36 else
37 {
38 return false; //False if keyword is not found
39 }
40 }
41 public boolean equals(Document other) //Method that compares two object that's type Document
42 {
43 if(this.content.equalsIgnoreCase(other.content))
44 {
45 return true; //True if two documents are same
46 }
47 else
48 {
49 return false; //False if two documents are different
50 }
51 }
52 }
53
54 class Email extends Document
55 {

56 //Below are the variables for Email class

57 private String sender;
58 private String recipient;
59 private Date date; //date of the email using the Date util package
60 private String subject; //email subject
61 private String cc; //list of people to be included on the email
62 boolean isSent; //specifies if email has been sent
63

64 //CONSTRUCTOR initializing instance variables and in given parameters
65 public Email(String text, String sender, String recipient, String subject, String cc) //Constructor with the variables listed above
66 {
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 code
81 return cc; //unsure of this code
82 }
83 //GETTER METHODS
84 public boolean getSent() //returns the instance variable isSent
85 {
86 return isSent;
87 }
88 public String getSender() //returns the instance variable sender
89 {
90 return this.Sender;
91 }
92 public String getRecipient() //returns the instance variables recipient
93 {
94 return this.Recipient;
95 }
96 public String getSubject() //returns the instance variable subject
97 {
98 return this.Subject;
99 }
100 public String getCC() //returns the instance variable cc
101 {
102 return this.CC;
103 }
104 public Date getDate() //returns the date instance variable
105 {
106 return this.Date;
107 }
108 //SETTER METHODS
109 public void setSender(String s)
110 {
111 if(isSent == false) //checking instance variable isSent
112 {
113 sender = s; //if false then email is not sent and sender can still be modified
114 }
115 else //or else it's true and sender cannot be modified
116 {
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 isSent
123 {
124 recipient = r; //if false then email is not sent and recipient can still be modified
125 }
126 else //or else it's true and recipient cannot be modified
127 {
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 isSent
134 {
135 subject = s; //if false then email is not sent and subject can still be modified
136 }
137 else //or else it's true and subject cannot be modified
138 {
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 isSent
145 {
146 cc = c; //if false then email is not sent and cc can still be modified
147 }
148 else //or else it's true and recipient cannot be modified
149 {
150 System.out.println("This email has been sent and CC cannot be modified.");
151 }
152 }
153 public String toString()
154 {
155 return
156 "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 class
162 }
163 public void modifyContent(String s)
164 {
165 if(isSent == false) //checking instance variable isSent
166 {
167 super.setContent(s); //if false then email is not sent and content can still be modified
168 }
169 else //or else it's true and content cannot be modified
170 {
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 }
182
183 class EmailDriver
184 {
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 object
189 Email e1 = new Email("Hello everyone, we will have a meeting tomorrow at 10", "Gita Faroughi","Alex","Meeting","");
190

191 //sending the email
192 e1.send();
193

194 //disply the details about the email
195 System.out.println(e1);
196 System.out.println("\n\n");
197

198 //searching the email for the email for the word tomorrow
199 boolean b = e1.contains("tmorrow");
200 if(b)
201 System.out.println("The word tomorrow was found in the email");
202 else
203 System.out.println("The word tomorrow was found in the email");
204

205

206 //displaying just the content(text) of the email
207 System.out.println("\nThe content of this email is: " + e1.getText());
208 System.out.println();
209 //modifying the content of the email
210 e1.modifyContent("bye");
211

212 //changing the recipient of the e1 email
213 e1.setRecipient("[email protected],[email protected]");
214 System.out.println();
215

216 //forwarding the email
217 Email forward = e1.forward("Alex", "Gita" ,"Maria");
218 System.out.println();
219

220 //printing the forwarded email
221 System.out.println("forwarded message\n"+ forward);
222 System.out.println();
223

224 //display the length of the text in the email
225 System.out.println("The number of the letters in the email is: " + e1.getDocumentLength());
226

227 //***********************************************************************
228 //your turn, refer to the provided documnet on the codes you need to write
229

230 }
231 }

Dec 08, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here