Question: Please do the following prompt in Java. Keep in mind the restrains and restrictions listed below. Manytimes,certaindatafiletypescanconsistoflarge amounts of repeated data. For instance, images can

Please do the following prompt in Java. Keep in mind the restrains and restrictions listed below.

Manytimes,certaindatafiletypescanconsistoflarge amounts of repeated data. For instance, images can have large runs of the same color. This can be easily compressed using a technique called run length encoding. With run length encoding, large amounts of repeated data are stored as the repeated data and the number of times to repeat it.

CreateaclassRunLengthEncodethatcontainsthemethod encode which takes one argument: a String to be encoded as described below.

ThereturnvalueshouldbeaStringwhichhasbeenencoded with the following algorithm:

Ifanycharacterisrepeatedmorethan4times,theentire set of repeated characters should be replaced with a slash '/', followed by a 2-digit number which is the length of the set of characters, and the character. For example, "aaaaa" would be encoded as "/05a". Runs of 4 or less characters should not be replaced since performing the encoding would not decrease the length of the string.

Notes

Letters are case sensitive. For example "AaAaAa" cannot be encoded.

You may only encode repeats of a single character, repeats of multiple characters cannot be encoded. For example "ababababab" cannot be encoded as "/05ab".

Constraints

input will have between 0 and 50 characters, inclusive.

input will consist only of letters 'a' - 'z' and 'A' - 'Z',

digits '0' - '9', the space character, and the characters in the following string: "{}[]():;'+=.,". (quotes are for clarity only and cannot be in the input string)

Examples

a) "aaaaa"

a.Returns: "/05a" b. The example stated above.

b) "aaaa"

a. Returns: "aaaa" b. Remember not to encode runs of length 4 or less.

c) "abcabcabcabcabc"

Returns: "abcabcabcabcabc"

Do not encode repeated segments of more than one

character

d) "if(a){if(b){if(c){if(d){if(e){5 deeeeeeep}}}}}"

a. Returns: "if(a){if(b){if(c){if(d){if(e){5 d/07ep/05}" e) ""

a. Returns: ""

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!