Write a program that uses the run-length coding method to compress and decompress a String. Create the
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:
• 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().
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch