Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

https: / / www . chegg.com / chat ? search = % 3 Cdiv % 3 E % 3 Cp % 3 EIn + a

https://www.chegg.com/chat?search=%3Cdiv%3E%3Cp%3EIn+a+text+messaging+system%2C+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%2C+the+device+ID+itself%2C+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.%0A%0AHere+is+a+sample+VALID+message%3A%0A04+1234+05+hello%0A%0AThe+first+two+digits+in+the+string+represent+the+length+of+the+device+ID+to+follow.%0A%0AThe+device+ID+is+the+number+of+characters+following+the+length.+Note+that+the+device+ID+may+not+be+limited+to+number+values.%0A%0AFollowing+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+%28such+as+letters%2C+numbers+or+symbols%29+and+may+include+spaces.%0A%0AThis+message+contains+one+word.%0A%0AHere+is+a+sample+INVALID+message%3A%0A06+a2b10+09+I%E2%80%99m+ready%0A%0AThe+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%2C+this+is+NOT+a+valid+message.%0A%0AThis+message+contains+two+words.%0A%0AThe+Message+class+represents+messages+in+this+system.+A+Message+must+have+a+device+ID%2C+the+length+of+the+ID%2C+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.%0A%0AConsider+the+code+below%3A%0A%0AMessage+msg1+%3D+new+Message%28%2208+abc123xy+16+Computer+Science%22%29%3B+%2F%2Fcreates+a+new+message+object%0Aboolean+msg1Valid+%3D+msg1.isValid%28%29%3B+%2F%2F+returns+true+for+a+valid+message%0AString+text+%3D+%2211+radio11a287+14%22%3B%0AMessage+msg2+%3D+new+Message%28text%29%3B%0Aboolean+msg2Valid+%3D+msg2.isValid%28%29%3B+%2F%2F+returns+false+for+an+invalid+message%0AMessage+msg3+%3D+new+Message%28%2204+92a1+16+Computer+Science%22%29%3B%0AMessage+msg4+%3D+new+Message%28%2203+x8r+21+Today+is+a+great+day%21%22%29%3B%0Aint+numWords+%3D+msg4.wordCount%28%29%3B+%2F%2Freturns+5%2C+the+number+of+words+in+the%0A%2F%2Ftext+message%0A%0AComplete+the+Message+class+by+writing+the+isValid%28%29+and+wordcount%28%29+methods.%0A%0Apublic+class+Message%7B%0A%0A+++++private+int+idLength%3B%0A+++++private+String+deviceID%3B%0A+++++private+int+msgLength%3B%0A+++++private+String+textMsg%3B%0A%0A+++++public+Message%28String+msg%29%7B%0A+++++%2F%2Fimplementation+not+shown%0A+++++%7D%0A%0A+++++public+boolean+isValid%28%29%7B%0A+++++%2F%2Fto+be+written%0A+++++%7D%0A%0A+++++public+int+wordCount%28%29%7B%0A+++++%2F%2Fto+be+written%0A+++++%7D%0A%0A%7D%3C%2Fp%3E%3C%2Fdiv%3E&searchid=b808ed7e-3f1e-4c3e-9eb7-abd9d898c941&strackid=005c9f3fe054&trackid=ba7ff16faabd

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions