Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This message contains two words. The Message class represents messages in this system. A Message must have a device ID , the length of the

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 radio11a28714";
Message msg2= new Message(text);
boolean msg2Valid = msg2.isValid(); // returns false for an invalid message
Message msg3= new Message("0492a116 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
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

More Books

Students also viewed these Databases questions

Question

What is the object of a corporation? From the film The Corporation

Answered: 1 week ago

Question

Understand human resource planning in an academic setting.

Answered: 1 week ago

Question

Analyze mentoring and career planning opportunities for academics.

Answered: 1 week ago