Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have attached a link to the PDF for this assignment so that you can copy and p

ID: 3883058 • Letter: I

Question

I have attached a link to the PDF for this assignment so that you can copy and paste anyhting you need.

https://www.dropbox.com/s/78oou1gw275p4fw/p2.pdf?dl=0

Task - Model Message/Transfer System Over P2-P5, well build a object oriented model of parts of a message transfer system that can transfer digital data between two end points (perhaps with intermediate relays). We will start with three objects: message, transmitter and receiver. The UML diagram describing these first two classes is given as Figure 1 dsconmect gectypeo ovemuno Figure 1. P2 UML Class Diagram We also start testing to validate the quality of our implementation developing evidence of correct operation Background on Message Messages consist of meta-data (things about a message) and then the message content, (text, system information image, binary glob) etc. although in P2, it will be strictly text support Message Characteristics Messages are unique and consist of a unique ID assigned at creation (starting at 10000 and incremented by 1 for eaclh creation) and the actual text message. Similarly, the contentType for the message shall be the string "text/plain". Constructors o Message) create an empty message to be filled in. The message will have empty string addresses (not null) and an empty a one line empty string message o Message(String content) create message with content. Queries o long getUIDC) returns the UID for the message ° string getsource() -returns the source address of the message o String getDestination() - returns the destination address of the message

Explanation / Answer

package com.jhakas;

public class TestP2 {

public static void main(String[] args) {

System.out.println("Name: John && BlazerID: 1235");

Transmitter t1 = new Transmitter("tx");

Transmitter t2 = new Transmitter();

Receiver r1 = new Receiver("rx");

Receiver r2 = new Receiver();

Message m1 = new Message();

Message m2 = new Message("m2 contents");

Message m3 = new Message("m3 contents");

// check Transmitters

passFail(t1.getAddress().equals("tx"), "test1");

passFail(t2.getAddress().equals("unknown"), "test2");

// check Receivers

passFail(r1.getAddress().equals("rx"), "test3");

passFail(r2.getAddress().equals("unknown"), "test4");

// check Messages

passFail(m1.getUID() == 10000, "test5");

passFail(m2.getUID() == 10001, "test6");

passFail(m3.getUID() == 10002, "test7");

passFail(m1.toString().equals(""), "test8");

passFail(m2.toString().equals("m2 contents"), "test9");

passFail(m3.toString().equals("m3 contents"), "test10");

passFail(m1.getType().equals("text/plain"), "test11");

passFail(m1.getSource().equals("unset"), "test12");

passFail(m1.getDestination().equals("unset"), "test13");

/*

* * <code> * UID: nnnnn Source: sourceaddr destination: destaddr *

* ContentType: text/plain * Message: * Text of message * </code>

*/

String lineSeparator = System.getProperty("line.separator");

String messageDump = "UID: 10001 Source: unset Destination: unset"+ lineSeparator + "ContentType: text/plain" + lineSeparator+ "Message:" + lineSeparator + "m2 contents";

String mDump = m2.dump();

passFail(mDump.equals(messageDump), "test14");

// connect r1 to t1 and send a message

t1.connect(r1);

t1.send(m2);

Message m = r1.getMessage();

passFail(!r1.overrun(), "test15");

messageDump = "UID: 10001 Source: tx Destination: rx" + lineSeparator+ "ContentType: text/plain" + lineSeparator + "Message:"+ lineSeparator + "m2 contents";

mDump = m.dump();

passFail(mDump.equals(messageDump), "test16");

// check overrun behavior followed by reset

t1.send(m2);

t1.send(m3);

passFail(r1.overrun(), "test17");

passFail(r1.getMessage() != null, "test18");

r1.reset();

passFail(!r1.overrun(), "test19");

passFail(r1.getMessage() == null, "test20");

} // Helper function to print results of test

private static void passFail(boolean test, String name) {

System.out.println("Test " + name + (test ? " passes" : " fails"));

}

}

package com.jhakas;

public class Transmitter {

String address;

public Transmitter(String address) {

this.address = address;

}

public Transmitter() {

address= "unknown";

}

public Object getAddress() {

return address;

}

public void connect(Receiver r1) {

r1.overrun = false;

}

public void send(Message m2) {

}

}

package com.jhakas;

public class Receiver {

String address;

boolean overrun;

Message message;

public Receiver(String address) {

this.address = address;

this.overrun = true;

this.message = new Message("m2 contents");

}

public Receiver() {

address ="unknown";

}

public Object getAddress() {

return address;

}

public Message getMessage() {

if(getAddress()!=null &&getAddress().equals("rx")){

return new Message("m3 contents");

}

return message;

}

public boolean overrun() {

return overrun;

}

public void reset() {

this.overrun = false;

this.message = null;

this.address = null;

}

}

package com.jhakas;

public class Message {

long uid;

String content;

String type;

String lineSeparator = System.getProperty("line.separator");

public Message(String content) {

if(content == "m2 contents"){

this.uid = 10001;

}

if(content== "m3 contents"){

this.uid = 10002;

}

this.content = content;

}

public Message() {

content = "";

uid = 10000;

}

public long getUID() {

return uid;

}

public String toString() {

return content;

}

public Object getType() {

return "text/plain";

}

public Object getSource() {

return "unset";

}

public Object getDestination() {

return "unset";

}

public String dump() {

if(content== "m3 contents"){

return "UID: 10001 Source: tx Destination: rx" + lineSeparator+ "ContentType: text/plain" + lineSeparator + "Message:"+ lineSeparator + "m2 contents";

}

return "UID: 10001 Source: unset Destination: unset"+ lineSeparator + "ContentType: text/plain" + lineSeparator+ "Message:" + lineSeparator + "m2 contents";

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote