Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In a text messaging system, data is sent from one device to another. Devices are recognized by a unique device ID . The format of
In a text messaging system, data is sent from one device to another. Devices are recognized by a unique device ID The format of the message is sent as a string with information about the number of characters in the device ID the device ID itself, the number of characters in the text message and the text message that is being sent with each part being separated by a space. The system uses this information to send the message to the correct device and the receiving device displays only the text message. The number of words in the text message is also useful. A word is defined by strings separated by spaces.
Here is a sample VALID message:
hello
The first two digits in the string represent the length of the device ID to follow.
The device ID is the number of characters following the length. Note that the device ID may not be limited to number values.
Following the device ID is the length of the text message and then the text message itself. The text message may be any combination of characters such as letters, numbers or symbols and may include spaces.
This message contains one word.
Here is a sample INVALID message:
ab Im ready
The first two values indicate the device ID length. The device ID is ab which has a length of This does not match the specified length Thus, this is NOT a valid message.
This message contains two words.
The Message class represents messages in this system. A Message must have a device ID the length of the ID the length of the message and the text message being sent in order to be a valid message sent through the system. The Message class must determine if a message is valid in order to send a message. A valid message is one where the device ID length matches the given length in the message string and the text message length matches the length of the supplied text message. The text message consists of one or more words where the length of the text message string is at least one character.
Consider the code below:
Message msg new Message abcxy Computer Science"; creates a new message object
boolean msgValid msgisValid; returns true for a valid message
String text radioa;
Message msg new Messagetext;
boolean msgValid msgisValid; returns false for an invalid message
Message msg new Messagea Computer Science";
Message msg new Message xr Today is a great day!";
int numWords msgwordCount; returns the number of words in the
text message
Complete the Message class by writing the isValid and wordcount methods.
public class Message
private int idLength;
private String deviceID;
private int msgLength;
private String textMsg;
public MessageString msg
implementation not shown
public boolean isValid
to be written
public int wordCount
to be written
dont use arrays or the split method. make it very basic
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started