Question: Program Requirement 1. You have to implement two classes namely, Encoder and FileEncoder. Both classes do not contain the main method. 2. Encoder contains at
Program Requirement 1. You have to implement two classes namely, Encoder and FileEncoder. Both classes do not contain the main method.
2. Encoder contains at least the following method: public static String encode(String word) This method will convert a word, which is the parameter, to the corresponding binary string. For example, the method returns 1111111111001010011111110 if the word is letter.
3. FileEncoder contains at least the following constructor and method: public FileEncoder(String inFile, String outFile) This constructor gets the paths of the input file and the output file in the first and second parameters respectively. public void convert() This method takes no parameter and returns no value. This file converts the content of the input file and print the results to output file.
4. FileEncoder must use Encoder to encode the input file.
5. FileEncoder and Encoder will be tested using the class TestEncoder.



And the main method is in TestEncoder.Java:
import java.util.Scanner; public class TestEncoder { public static void main(String[] args) { System.out.print("Input file: "); Scanner sc = new Scanner(System.in); String inFilename = sc.next(); System.out.print("Output file: "); String outFilename = sc.next(); FileEncoder fileEncoder = new FileEncoder(inFilename, outFilename); fileEncoder.convert(); System.out.println("Done"); } }Description There are 26 letters in English. To represent these 26 letters in binary string (a string with 0 or l only), it needs to have 5 bits to encode each letter (23-32>26. For example, we may use 00000, 00001, 11001 to encode a, b, and z respectively. This is called fixed-length encoding since every letter uses the same number of bits. Some letters appear more than others do in common words. The following table shows a study on the frequency of letters based on 40,000 words: Letter | Count | Frequencv(% Encodin Bits used 21912 16587 14810 14003 13318 12666 11450 10977 10795 7874 7253 5246 4943 4761 4200 3853 3819 3693 3316 2715 2019 1257 315 205 2.02 9.10 8.12 7.68 7.31 6.95 6.28 6.02 5.92 4.32 3.98 2.88 2.71 10 110 1110 6 12 2.30 2.11 2.09 16 18 1.49 0.69 0.17 0.11 0.10 0.07 23 24 25 128 (source: https://www.math.cornell 2004/cryptography/subs/frequencies.html Variable-length encoding aims at using different number of bits to encode letters. If we use fewer bits to encode those frequent letters but more bits to encode those infrequent letters, the resultant encoded string of a word may still be shorter. For e length encoding requires 30 bits because there are 6 letters. In variable-length coding, the encoded binary string is "1111111111001010011111110", which is just 25 bits, according to the encoding scheme shown in the above table. As a result, this can save resource in data transmission. xample, to encode the word "letter, fixed- Your Task You are asked to write a Java program to encode the words contained in an input file and save the encoded binary string according to the encoding scheme depicted in the above table to an output file. The program may contain any number of classes. Input File Format The input file must contain one or more lines. Each line must contain one or more words in lowercase letters. Two words in the same line are separated by a single space. In other words, the file contains only lowercase letters and space. The following shows a sample input file: ere are anly tve ways to live your life one is as though nathing i Output File Format The output file must contain same line as the input file. Each line must contain the binary string of the words of the corresponding line in the same order. Two binary stings in the same line are separated by a single space. The following shows a part of the output file: 1300 310133 Program Requirement 1. You have to implement two classes namely, Encoder and FileEncoder. Both classes do not contain the main method. Encoder contains at least the following method: 2. public static String encode (String word) This method will convert a word, which is the parameter, to the corresponding binary string. For example, the method returns "1111111111001010011111110" if the word is letter". FileEncoder contains at least the following constructor and method: 3. public FileEncoder (String inFile, string outFile) This constructor gets the paths of the input file and the output file in the first and second parameters respectively. public void convert) This method takes no parameter and returns no value. This file converts the content of the input file and print the results to output file. FileEncoder must use Encoder to encode the input file. FileEncoder and Encoder will be tested using the class TestEncoder. 4. 5
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
