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

JAVA PROGRAM: ( Model Message/Transfer System) Build a object oriented model of

ID: 3883064 • Letter: J

Question

JAVA PROGRAM: (Model Message/Transfer System)

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). Start with three objects: message, transmitter. The UML diagram describing these first two classes is given as Fig. 1

Fig, 1

Messages consist of meta-data (things about a message) and then the message content, (text, system information, image, binary glob) etc. although in this program, 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 each creation) and the actual text message. Similarly, the contentType for the message shall be the string “text/plain”.

>Constructors:

-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.

-Message(String content) - create message with content.

>Queries:

-long getUID() - returns the UID for the message

-String getSource() - returns the source address of the message

-String getDestination() - returns the destination address of the message

-String toString() - returns the message content

-String getType() - returns “plain/text” presently denoting a collection of text lines.

-String dump() - returns a multi-line representation of the message

UID: nnnnn Source: sourceaddr Destination: destaddr

ContentType: text/plain

Message:

>>Text of message<<

>Commands:

-void setContent(String text) - replace existing message content

-void setSource(String address) - set the source address of the message

-void setDestination(String address) - set the destination address of the message

Receiver Characteristics:

A receiver is an endpoint of a transmission. For this program, a receiver may be connected to a transmitter. The transmitter delivers a message to the receiver. The receiver can note that a message is available and it can be retrieved by “getting the message”. In this program, if a second message comes in before the first is retrieved then an overrun condition exists. The overrun condition can be cleared with with a reset which will also clear any available message.

>Constructors

-Receiver() - create a receiver with an address of “unknown”

-Receiver(String address) - create a receiver with specified address”

>Queries

-String getAddress() - returns address of receiver

-boolean overrun() - returns true if one or more messages are delivered while the receiver is holding a message

-boolean available() - returns true if message available

>Commands

-void deliver( Message message) - deliver message into Receiver

-Message getMessage() - returns message from receiver if available or null otherwise

-void reset() - resets the overrun condition on the receiver and clears any stored message inside the receiver

Transmitter Characteristic:

A transmitter is an origination point for a message communication. In this program, a receiver may be directly connected to the transmitter. The transmitter can send a message to the connected receiver attaching its address as the source address of the message and the receiver’s address as the destination address.

>Constructors

-Transmitter() - create a transmitter with the source address “unknown”.

-Transmitter(String address) - create a transmitter with the specified address.

>Queries

-String getAddress() - return the address of the transmitter

>Commands

-void connect(Receiver receiver) - connect to the specified receiver so that messages can be sent to it. Only one connection at a time is possible for this program. Fail silently if there are issues.

-void send(Message message) - send message to connected receiver if any (fail silently), apply addresses for source and destination

-void disconnect() - disconnect from the connected receiver if any (fail silently)

Note:

Like all other modeling objects, Message , Receiver and Transmitter classes should not not contain I/O.

***Static Variable:

Static variables (variables outside any method and declared static) belong to the class not to an object of the class. That means they hold the same value for all objects (or other references) and be used for things such as counters to keep up with number of objects constructed, next serial number, etc.

private static int count = 10;

declares an integer variable which starts at 10 but any changes made to count will stick. The initialization is only done at the start of the program.

Also determining proper line separation.

Transmiter Transmitter Transmitter(String addr) getAddr0 send(Message message) Message ·conect(Receiver receiver) +Message0 +Message(String line) GeUID + geeSource0 geDestination + toString0 + dump) + setcontentSaring ine) Receiver setSource(String address) Receiver0 Receiver(Saring addr egetAddr e overnun - avalable0 delivertMessage message) getMessage reset

Explanation / Answer

Message class definition:

public class Message {
static long messageID = 0;
String message;
String contentType = "text/plain";
String source;
String destination;
  
// Constructors
Message(){
message = "";
}
Message(String msg){
message = msg;
}
// Accessors
public long getUID() {
return messageID;
}
public String getSource() {
return source;
}
public String getDestination() {
return destination;
}
public String getType() {
return contentType;
}
public String toString(){
return "Message " + messageID+ ": "+message;
}
public String dump(){
return "Message " + messageID+ ": "+message + " From: "+ source + " to: "+destination;
}
  
// Mutators
public void setContent(String text){
message = text;
}
void setSource(String address) {
source=address;
}
void setDestination(String address) {
destination=address;
}
}