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, 22.06.2019 03:00
Which action describes an aspect of technological design?
Answers: 1
question
Computers and Technology, 23.06.2019 11:00
What is the name of the sound effect that danny hears
Answers: 1
question
Computers and Technology, 23.06.2019 19:00
This question involves a class named textfile that represents a text file. public class textfile { private string filename; private string filename; private arraylist words; // constructors not shown // postcondition: returns the number of bytes in this file public int filesize() { } // precondition: 0 < = index < words.size() // postcondition: removes numwords words from the words arraylist beginning at // index. public void deletewords(int index, int numwords) { } // precondition: 0 < = index < = words.size() // postcondition: adds elements from newwords array to words arraylist beginning // at index. pub lic voidaddwords(int index, string[] newwords) { } // other methods not shown } complete the filesize() method. the filesize() is computed in bytes. in a text file, each character in each word counts as one byte. in addition, there is a space in between each word in the words arraylist, and each of those spaces also counts as one byte. for example, suppose the words arraylist stores the following words: { mary had a little lamb; its fleece was white as snow. } the filesize() method would compute 4 + 3 + 1 + 6 + 5 + 4 + 6 + 3 + 5 + 2 + 5 as the sum of the lengths of each string in the arraylist. the value returned would be this sum plus 10, because there would also be 10 spaces in between the 11 words. complete the filesize() method below: // postcondition: returns the number of bytes in this file public int filesize() { }
Answers: 1
question
Computers and Technology, 24.06.2019 01:00
Mastercard managers are motivated to increase (1) the number of individuals who have and use a mastercard credit card, (2) the number of banks and other clents who issue mastercards to customers and/or employees, and (3) the number of locations that accept mastercard payments. discuss how mastercard could use its data warehouse to it expand each of these customer bases.
Answers: 3
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, 18.10.2021 02:00
question
Mathematics, 18.10.2021 02:00
question
History, 18.10.2021 02:00
question
Chemistry, 18.10.2021 02:00
question
History, 18.10.2021 02:00
question
Physics, 18.10.2021 02:00
question
Mathematics, 18.10.2021 02:00
Questions on the website: 13722360