ASSIGNMENT 15

 (TAP 4 Scns280-1.pages) & (TAP4.cns346.pages) 

//URL: https://dotnetfiddle.net/ using System; public class Program { class Contact{ private String name; private string phone; private Message [] messages = new Message[1000]; public String getName(){ return name; } public void setName(String name){ this.name = name; } public String getPhone(){ return phone; } public void setPhone(String phone){ this.phone = phone; } public Contact(String phone, String name){ this.phone = phone; this.name = name; } public String toString(){ return phone + ” : “+name; } public void sendMessage(Contact ct,Message msg){ msg.sendMsg(ct, msg); } public Message receiveMessage(Contact ct){ Message msg = new TextMsg(ct); Console.WriteLine(“new msg from ” + ct.getName()); Message rmsg = msg.receiveMsg(ct); return rmsg; } } abstract class Message{ protected Contact sender; protected int time_seq; public int getTime(){ return time_seq; } public Contact getSender(){ return sender; } public abstract void sendMsg(Contact ct,Message msg); public abstract Message receiveMsg(Contact ct); public abstract String toString(); } class TextMsg : Message{ private String text; public TextMsg(Contact ct, int time, String text){ this.sender = ct; this.time_seq = time; this.text = text; } public TextMsg(Contact ct){ this.sender = ct; } override public void sendMsg(Contact ct, Message msg){ TextMsg tmsg = (TextMsg) msg; Console.WriteLine(“Message: ” + tmsg.toString() +” – to ” + ct.getName() +” is sent.”); } override public Message receiveMsg(Contact ct){ Console.WriteLine(“Message TEST MESSAGE from contact ” + ct.getName() +” is received.”); Message msg = new TextMsg(ct, 12, “how are you doing?”); return msg; } override public String toString(){ return “sender” + sender.toString()+”; id:”+time_seq + “, body: “+text; } } class VoiceMsg : Message{ private Audio msg; public VoiceMsg(Contact ct, int time, Audio audioMsg){ this.sender = ct; this.time_seq = time; this.msg = audioMsg; } override public void sendMsg(Contact ct, Message msg){ Console.WriteLine(“Voice Message: ” + msg.toString()+ ” – to ” + ct.getName() +” is sent.”); } override public Message receiveMsg(Contact ct){ Console.WriteLine(“Message Voice MESSAGE from contact ” + ct.getName() +” is received.”); Audio audioMsg = new Audio(“TEST Voice MESSAGE”); Message msg = new VoiceMsg(ct, 13,audioMsg ); return msg; } override public String toString(){ return msg.toString(); } } class Audio{ private String audio; public Audio (String msg){ this.audio = msg; } public String getAudio(){ return audio; } public void setAudio(String audio){ this.audio = audio; } public String toString(){ return audio; } } public static void Main() { Contact ct1 = new Contact(“6666”, “Fatma”); Contact ct2 = new Contact(“5555”, “Ismail”); Contact ct3 = new Contact(“4444”, “Ali”); Message ct1Toct2Msg = new TextMsg(ct2, 1, “Hello, Ismail”); ct1.sendMessage(ct2, ct1Toct2Msg); Message ct2Toct3Msg = new VoiceMsg(ct3, 4, new Audio(“Hello, Ali”)); ct1.sendMessage(ct3, ct2Toct3Msg); Message msg = ct1.receiveMessage(ct2); Console.WriteLine(“received message is: ” + msg.toString()); Message msg2 = ct1.receiveMessage(ct3); Console.WriteLine(“received message is: ” + msg2.toString()); } }