subject

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:
04 1234 05 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:
06 a2b10 09 I’m ready
The first two values 06 indicate the device ID length. The device ID is a2b10 which has a length of 5. This does not match the specified length 06. 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 msg1 = new Message("08 abc123xy 16 Computer Science"); //creates a new message object
boolean msg1Valid = msg1.isValid(); // returns true for a valid message
String text = "11 radio11a287 14";
Message msg2 = new Message(text);
boolean msg2Valid = msg2.isValid(); // returns false for an invalid message
Message msg3 = new Message("04 92a1 16 Computer Science");
Message msg4 = new Message("03 x8r 21 Today is a great day!");
int numWords = msg4.wordCount(); //returns 5, 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 Message(String msg){
//implementation not shown
}
public boolean isValid(){
//to be written
}
public int wordCount(){
//to be written
}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 02:00
Read this excerpt from helen keller’s autobiography, the story of my life. have you ever been at sea in a dense fog, when it seemed as if a tangible white darkness shut you in, and the great ship, tense and anxious, groped her way toward the shore with plummet and sounding-line, and you waited with beating heart for something to happen? i was like that ship before my education began, only i was without compass or sounding-line, and had no way of knowing how near the harbour was. "light! give me light! " was the wordless cry of my soul, and the light of love shone on me in that very hour. . the morning after my teacher came she led me into her room and gave me a doll. the little blind children at the perkins institution had sent it and laura bridgman had dressed it; but i did not know this until afterward. when i had played with it a little while, miss sullivan slowly spelled into my hand the word "d-o-l-l." i was at once interested in this finger play and tried to imitate it. when i finally succeeded in making the letters correctly i was flushed with childish pleasure and pride. running downstairs to my mother i held up my hand and made the letters for doll. i did not know that i was spelling a word or even that words existed; i was simply making my fingers go in monkey-like imitation. in the days that followed i learned to spell in this uncomprehending way a great many words, among them pin, hat, cup and a few verbs like sit, stand and walk. based on this excerpt, which words best describe helen keller?
Answers: 2
question
Computers and Technology, 24.06.2019 01:30
Hazel has just finished adding pictures to her holiday newsletter. she decides to crop an image. what is cropping an image?
Answers: 1
question
Computers and Technology, 24.06.2019 14:00
In simple terms, how would you define a protocol?
Answers: 2
question
Computers and Technology, 24.06.2019 14:30
When workers demonstrate patience, are able to manage there emotions, and get along with other employees, which skills are being displayed?
Answers: 1
You know the right answer?
In a text messaging system, data is sent from one device to another. Devices are recognized by a uni...
Questions
question
Mathematics, 12.12.2020 16:40
question
Arts, 12.12.2020 16:40
question
Mathematics, 12.12.2020 16:40
Questions on the website: 13722363