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

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

So far this is the code for Message class:

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; } }

Still need Receiver and Transmitter class:

For Receiver class:

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

For Transmitter class:

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 receivers 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)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!