1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Anni [7]
3 years ago
7

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
}
Computers and Technology
1 answer:
Oliga [24]3 years ago
4 0

Answer:

public int wordCount() {

       String[] arr = textMsg.split(" ", 0);

       return arr.length();

   }

public boolean isValid() {

       if (idLength == deviceID.length()) {

           if (msgLength == textMsg.length()) {

               return true;

           } else {

               return false;

           }

       return false;

   }

Explanation:

The Java source code defines two methods in a class named Message namely; isValid() and wordCount(). The isValid() method evaluates the validity of a message sent to return a boolean value while the wordCount() counts and returns the number of words in the message.

You might be interested in
In 25 words or fewer, identify what calendar feature the recurring task function copies.
alexdok [17]
Shhsnanwnwnsjssnsnnwnsn
7 0
4 years ago
Is this photo considered rim photography?
steposvetlana [31]

wheres the picture??

8 0
3 years ago
Who is the orange and white Foxy that looks like Mangle but instead of pink its orange
Helga [31]

Answer:

Its Lolbit

Explanation:

Lolbit is an animatronic from Five Nights at Freddy's: Sister Location. It is a recolored version of Funtime Foxy's disembodied head, appearing as a minor Easter Egg from the main game.

7 0
3 years ago
Insert Into invoices (vendor_id, invoice_number, invoice_total, payment_total, credit_total, terms_id, invoice_date, invoice_due
FinnZ [79.3K]

Answer:

There are few values in the list. So, this insert statement will not be executed.

Explanation:

4 0
3 years ago
Read 2 more answers
According to chronology, arrange the steps that you need to take during the installation of a ram stick?
MAXImum [283]

Answer:

first off you need to take of the screws make sure its unpluged and you open up to see the mother bored

Explanation:

6 0
3 years ago
Other questions:
  • Which of the following best describes the Distribution Mix?
    15·1 answer
  • What are small applications that can be accessed over the web?
    7·2 answers
  • Powerpoint s _____ feature allows you to set the timing for a video clip
    12·1 answer
  • State 3 file formats explain them in an understanding manner apart from Microsoft word and PDF
    5·1 answer
  • Once artwork is inserted into a placeholder, it can be moved around on a slide. True False
    9·1 answer
  • Given the following HTML form snippet of markup, which of the following user inputs would meet the regular expression rule writt
    7·1 answer
  • Write a program to accept two numbers<br>in two lines and find Square root of Squares<br>of thion​
    13·1 answer
  • Without net neutrality, which of these situations might occur? (Select all that apply.) a cable company might charge different b
    5·1 answer
  • একটি ডকুমেন্ট তৈরী করে ড্রাইভে সেভ করার পদ্ধতি বর্ণনা করো
    10·1 answer
  • Write a program code which asks for 80 numbers between 100 and 1000 to be entered.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!