Question
2. Compress Write your code in the file Compress.java, your class must have this exact name with C capitalized. This problem requires you to write
2. Compress Write your code in the file Compress.java, your class must have this exact name with C capitalized. This problem requires you to write a compression algorithm as described below. Run-length encoding (RLE) is a simple "compression algorithm" (an algorithm which takes a block of data and reduces its size, producing a block that contains the same information in less space). It works by replacing repetitive sequences of identical data items with short "tokens" that represent entire sequences. Applying RLE to a string involves finding sequences in the string where the same character repeats. Each such sequence should be replaced by a "token" consisting of: the number of characters in the sequence the repeating character If a character does not repeat, it appears as a single character in the compressed string with no number preceding it. For example, consider the following string: qwwwwwwwwweeeeerrtyyyyyqqqqwEErTTT After applying the RLE algorithm, this string is converted into: q9w5e2rt5y4qw2Er3T In the compressed string, "9w" represents a sequence of 9 consecutive lowercase "w" characters. "5e" represents 5 consecutive lowercase "e" characters, etc. Write a method called compress that takes a string as input, compresses it using RLE, and returns the compressed string. Case matters - uppercase and lowercase characters are to be considered distinct. You may assume that there are no digit characters in the input string. There are no other restrictions on the input - it may contain spaces or punctuation. There is no need to treat non-letter characters any differently from letters. For this assignment, your class Compress.java must include a method compress with the following method header: public static String compress ( String original ) You may write your own main method to test your appendNTimes method. Autolab will ignore your main method. Note: 3 submissions without deductions; 5 points deduction for every submission thereafter.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started