Question: Consider the code below: Message msg 1 = new Message ( 0 8 abc 1 2 3 xy 1 6 Computer Science ) ;

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!