Repository navigation
Expand file tree
/
Copy pathtask1.java
More file actions
72 lines (57 loc) · 1.69 KB
/
Copy pathtask1.java
File metadata and controls
72 lines (57 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
class Message {
String text;
public Message(String text) {
this.text = text;
}
public String getText() {
return text;
}
public String toString() {
return text;
}
}
class SMS extends Message {
String recipientContactNo;
public SMS(String recipientContactNo, String text) {
super(text);
this.recipientContactNo = recipientContactNo;
}
public String getRecipientContactNo() {
return recipientContactNo;
}
public String toString() {
return "To: " + recipientContactNo + "\nMessage: " + text;
}
}
class Email extends Message {
String sender;
String receiver;
String subject;
public Email(String sender, String receiver, String subject, String text) {
super(text);
this.sender = sender;
this.receiver = receiver;
this.subject = subject;
}
public String getSender() {
return sender;
}
public String getReceiver() {
return receiver;
}
public String getSubject() {
return subject;
}
public String toString() {
return "From: " + sender + "\nTo: " + receiver + "\nSubject: " + subject + "\nMessage: " + text;
}
}
public class task1 {
public static void main(String[] args) {
SMS sms = new SMS("03116014199", "Hey, are you coming to the party tonight?");
Email email = new Email("shahzai@example.com", "ilyas@example.com", "Weekend Plans", "Let's go hiking this weekend.");
System.out.println(sms.toString());
System.out.println();
System.out.println(email.toString());
}
}