Question

In: Computer Science

Write a program which compresses a given string of 1s and 0s and uncompress the string...

Write a program which compresses a given string of 1s and 0s and uncompress the string that was compressed. Use the run-length compression technique which replaces runs of 0s with a count of how many 0s.

The interactive input/output should allow users to select and run required processes.

The assignment submission on Blackboard should be as CIS_232_Project_LastName.zip file and include:

project report file: ProjectReportLastName.doc

program’s source file: ProjectLastName.java

program’s bytecode file:   ProjectLastName.class

and any other relevant files.

The project report should be prepared by using word processing software. To write a program you should complete and include in your assignment report the following steps:

      Title:

            Student’s name:
            CIS 232 Introduction to Programming  

            Programming Project
            Due Date: November 30, 2020

            Instructor Dr. Lomako:

  1. Problem statement - A clear and concise description of the problem.
  2. Analysis - An explanation of what the problem statement tells you to do and description of the general method used to solve the problem.
  3. Design – Explanation of the algorithm designed to solve the problem. Concentrate on the general program logic that includes:
    1. Structure chart of the program.
    2. Description of data transmission between the modules.
    3. Description of the algorithms using pseudo code or flowchart.
  4. Development of the program. Comment your code well at the top of each method, class, etc. including the title, inputs and outputs, etc. Comments are important because the well commented functions/logics are helpful to other programmers to understand the code better.
  5. Test the program. Using the test data show testing results and compare them with what you expected to have.
  6. Run the program to solve the problem. Show and explain results. The first lines of the output should have the title information.
  7. Prepare user instructions of your program.

Solutions

Expert Solution

The following program asks the user to enter a string of 0's and 1's. It then computes the running length of 0's and 1's. And then finally displays the character and its running length as the encoded form of the message.

For example, if the string is 00011111, then the encoded message will be 0315, that means the character 0 has a running length of 3 and the character 1 has a running length of 5.

Program:

import java.util.*;
public class ProjectLastName
{
   public static void main(String[] args)
   {
       Scanner sc= new Scanner(System.in);
       System.out.print("Enter the string: ");
       String str=sc.nextLine();
       int l=str.length();
       int count;
       System.out.print("Encoded string is: ");
       for(int i=0;i<l;i++)
       {
           count=1;
           while (i<l-1&&str.charAt(i)==str.charAt(i+1))
           {
count++;
i++;
}
System.out.print(str.charAt(i));
System.out.print(count);
       }
   }
}


Program Screenshot:

Output Screenshot:

1.

2.


Related Solutions

A string of 0s and 1s is to be processed and converted to an even-parity string...
A string of 0s and 1s is to be processed and converted to an even-parity string by adding a parity bit to the end of the string.(For an explanation of the use of parity bits, see Example 30 in Chapter 9.) The parity bit is initially 0. When a 0 character is processed, the parity bit remains unchanged. When a 1 character is processed, the parity bit is switched from 0 to 1 or from 1 to 0. Prove that...
(C++) Write a program that randomly fills in 0s and 1s into a 5-by-5 matrix,prints the...
(C++) Write a program that randomly fills in 0s and 1s into a 5-by-5 matrix,prints the matrix,and finds which row and column with more 1s and display that row and column number.            
P [1r / 0s] = 0.03 and P [0r / 1s] = 0.02 conditional in an...
P [1r / 0s] = 0.03 and P [0r / 1s] = 0.02 conditional in an asymmetric binary communication channel available. The probability of sending 0 in this channel is P [1s] = 0.56. 25 bits from this channel It has been sent. Accordingly, find the possibility of fewer than 3 faulty bits in the 25 bits transmitted. Note: 0s : 0 transmit, 1s : 1 transmit, 0r : 0 represent, 1r : 1 represent running events.
The transmitter transmits either an infinite sequence of 0s with a probability 2/3 or 1s with...
The transmitter transmits either an infinite sequence of 0s with a probability 2/3 or 1s with a probability 1/3. Each symbol, regardless of the others and the transmitted sequence is identified by the receiving device with an error with a probability 0.25. i) Given that the first 5 identified symbols are 0s, find the probability P (000000 | 00000) that the sixth received symbol is also zero. b) Find the average value of a random variable equal to the number...
Advance programing in java Qn1 1.True or False: (a) A sequence of 0s and 1s is...
Advance programing in java Qn1 1.True or False: (a) A sequence of 0s and 1s is called a decimal code. (b) ZB stands for zero byte. (c) The CPU stands for command performing unit. (d) Every Java application program has a method called main. (e) An identier can be any sequence of digits and letters. (f) Every line in a program must end with a semicolon. 2. Explain the two most important benets of the Java language 3 Explain the...
IN PYTHON Given a string with duplicate characters in it. Write a program to generate a...
IN PYTHON Given a string with duplicate characters in it. Write a program to generate a list that only contains the duplicate characters. In other words, your new list should contain the characters which appear more than once. Suggested Approach Used two nested for loops. The first for loop iterates from 0 to range(len(input_str)). The second for loop iterates from first_loop_index + 1 to range(len(input_str)). The reason you want to start at first_loop_index + 1 in the nested inner loop...
Write a program that counts the letters in a given string and then display the letter...
Write a program that counts the letters in a given string and then display the letter count in order from high to low. The program should: Display a message stating its goal Prompt the user to enter a string input Count the letters in the string (hint: use dictionaries) Display the letter count in order from high to low (sort your letter count) For example, for the input Google the output should be G - 2 O - 2 E...
Write a Python program which prompts the user to input a string. Then, print the string...
Write a Python program which prompts the user to input a string. Then, print the string in reverse to the terminal Sample output Please enter a word: "zeus" The reverse of zeus is suez Hint: There are several ways to accomplish this. Recall that a string is an itterable object and therefore can be used with a for loop
A population contains nine million 0s and seven million 1s. What is the sampling distribution of...
A population contains nine million 0s and seven million 1s. What is the sampling distribution of the sample mean when the sample size is n=5? Let X be the number of 1s. Complete the chart below. X ​P(X) x 0 nothing nothing 1 nothing nothing 2 nothing nothing 3 nothing nothing 4 nothing nothing 5 nothing nothing ​(Round to three decimal places as​ needed.)
Given a string, such as x = ‘itm330’, write a Python program to count the number...
Given a string, such as x = ‘itm330’, write a Python program to count the number of digits and the number of letters in it. For example, in ‘itm330’, there are 3 letters and 3 digits. Hint: Very similar to page 11 on the slides. To check if a character c is a digit, use c.isdigit(). If c is a digit, c.isdigit() will be a True.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT