Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello I have a Java Programming Homework i cant write the code could you help me please.there is urgency of assignment In this assignment you

Hello I have a Java Programming Homework i cant write the code could you help me please.there is urgency of assignment

In this assignment you will encode a simple compression algorithm for text files. The purpose of compression algorithms is to show the characters in the file with fewer bits than 8 or 16 bits and store them in the compressed file. The algorithm consists of the following steps

Read the file and determine how many different characters.

2. Match each character to a different number in the binary sequence. (How many bits do you need for each character to do this?)

Save the entire file as a string with the bits specified above.

Convert all 8-character substrings of this string to a byte sequence, translating the decimal sequence. (The above-formed string 8 may not be multiples of the size)

Write this byte array (and some extract information) to a binary file.

At the end of the algorithm, the resulting file is a compressed version of the text file. For example, let's look at the text file, whose contents are just the following sentence.

Programming is fun.

There are 13 different characters in the file: {P,r,o,g,a,m,i,n,s,f,u,., }At least 4 bits to display 13 different numbers in binary format

there is a need. So character - number mapping would be as follows:

P : 0000

r : 0001

o : 0010

g : 0011

a : 0100

m : 0101

i : 0110

n : 0111

s : 1000

f : 1001

u : 1010

. : 1011

: 1100

Thus, the output of the file can be represented by the following string.

0000000100100011000101000101010101100111001111000110100011001001101001111011

You need to insert this string into the byte array in 8 character substrings. The string consists of a total of 19 * 4 = 76 bits and can be stored in 10 bytes (the last byte remains 4 bits). All the (different) characters in the text file, their codes, and the 10 bytes are written to the binary file in sequence, and the time compression will be finished. In this first part of the file you will decide how to write this information yourself. You should write so that it takes up as little space as you can. (For this example, you will see that the compressed file is larger than the text file, so for this small file this method will not work, but it will provide algorithm compression for longer text files)

Of course, this algorithm needs to be able to open a compressed file with your program. Your code should work as below.

Enter command : Compress (C) | Open (O) | Exit (E)

C

Enter the file to be compressed: input.txt input.txt.S file is created.

Enter command : Compress (C) | Open (O) | CExit (E)

O

Enter the file to open: input.txt.S

input.txt file is created

Enter command : Compress (C) | Open (O) | Exit (E)

E

image text in transcribedimage text in transcribed

In this assignment you will encode a simple compression algorithm for text files. The purpose of compression algorithms is to show the characters in the file with fewer bits than 8 or 16 bits and store them im the compressed file. The algorithm consists of the following steps 1. Read the file and determime how many different characters 2. 2. Match each character to a different number im the bmary sequence. (How many bits do you need for each character to do this?) 3. Save the entire file as a string with the bits specified above. 4. Convert all S-character substrings of this string to a byte sequence, translating the decimal sequence. (The above- formed strng 8 may not be multiples of the size) 5. Write this byte array (and some extract information) to a binary file. At the end of the algorithm, the resulting file is a compressed version ofthe text file. For example, let's look at the text file whose contents are just the following sentence Programming is fun There are 13 different characters in the file: Progamjns.fu.., \Atleast 4 bits to display 13 different numbers in bmry format there is a need. So character-number mapping would be as follows P 0000 r 0001 0010 f: 1001 u 1010 . 1011 0011 a 0100 m 0101 i 0110 n 01 s 1000 1100 Thus, the output of the file can be represented by the following strng 0000000100100011000101000101010101100111001111000110100011001001101001111011 You need to insert this string into the byte array in 8 character substrings. The string consists of a total of 19 * 76 bits and can be stored in 10 bytes (the last byte remams 4 bits). All the (different) characters in the text file, their codes, and the 10 bytes are written to the binary file in sequence, and the time compression will be finished. In this first part of the file you will decide how to write this information yourself. You should write so that it takes up as little space as you can. (For this ex ample, you will see that the compressed file is larger than the text file, so for this small file this method will not work, but it will provide algorithm compression for longer text files) Ofcourse, this algorithm needs to be able to open a compressed file with y our program. Your code should work as below In this assignment you will encode a simple compression algorithm for text files. The purpose of compression algorithms is to show the characters in the file with fewer bits than 8 or 16 bits and store them im the compressed file. The algorithm consists of the following steps 1. Read the file and determime how many different characters 2. 2. Match each character to a different number im the bmary sequence. (How many bits do you need for each character to do this?) 3. Save the entire file as a string with the bits specified above. 4. Convert all S-character substrings of this string to a byte sequence, translating the decimal sequence. (The above- formed strng 8 may not be multiples of the size) 5. Write this byte array (and some extract information) to a binary file. At the end of the algorithm, the resulting file is a compressed version ofthe text file. For example, let's look at the text file whose contents are just the following sentence Programming is fun There are 13 different characters in the file: Progamjns.fu.., \Atleast 4 bits to display 13 different numbers in bmry format there is a need. So character-number mapping would be as follows P 0000 r 0001 0010 f: 1001 u 1010 . 1011 0011 a 0100 m 0101 i 0110 n 01 s 1000 1100 Thus, the output of the file can be represented by the following strng 0000000100100011000101000101010101100111001111000110100011001001101001111011 You need to insert this string into the byte array in 8 character substrings. The string consists of a total of 19 * 76 bits and can be stored in 10 bytes (the last byte remams 4 bits). All the (different) characters in the text file, their codes, and the 10 bytes are written to the binary file in sequence, and the time compression will be finished. In this first part of the file you will decide how to write this information yourself. You should write so that it takes up as little space as you can. (For this ex ample, you will see that the compressed file is larger than the text file, so for this small file this method will not work, but it will provide algorithm compression for longer text files) Ofcourse, this algorithm needs to be able to open a compressed file with y our program. Your code should work as below

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

Students also viewed these Databases questions