Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Graph Databases In Action

Authors: Dave Bechberger, Josh Perryman

1st Edition

1617296376, 978-1617296376

More Books

Students also viewed these Databases questions

Question

Prepare an electronic rsum.

Answered: 1 week ago

Question

Strengthen your personal presence.

Answered: 1 week ago

Question

Identify the steps to follow in preparing an oral presentation.

Answered: 1 week ago