Question
Write a program that uses the run-length coding method to compress and decompress a String. Create the following methods and add them to your class:
Write a program that uses the run-length coding method to compress and decompress a String.
Create the following methods and add them to your class:
• compress(String p) that compresses plain text p to cipher text c using the runlength coding method, where each letter appearing successively 3 or more times will be replaced by one occurrence of the letter followed by its count. If p = "abbbcc", then it should return "ab3cc", for example.
• decompress(String c) that decompresses c back to p. For example, "ab3cc" will be decompressed to "abbbcc".
The main method should use a loop that allows the user to enter a string and test the two methods repeatedly. You do not have to have a menu.
Note that you do not have to test with strings that contain characters other than lowercase letters and numbers. Strings that you are compressing should only have lowercase letters in them. Strings that you are decompressing should have lowercase letters and numbers as appropriate.
1. You must use a For loop to do the work in each method in this lab.
2. You may not use any concepts not yet taught in this course like arrays. Furthermore, nested loops aren’t needed to solve this problem.
3. The only built-in String methods you can use are length() and charAt().
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Below is an example of a Java program that implements the described runlength coding methods import ...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