Answered You can hire a professional tutor to get the answer.

QUESTION

Need help writing 2 classes for a comp sci assignment. The first class - private static void performCompression(String inputFileName, String ccName,

Need help writing 2 classes for a comp sci assignment.

The first class - private static void performCompression(String inputFileName, String ccName, String outputFilename);

The second class is the decompression class, which does the opposite of the compression class.

This class essentially takes as input a file containing a String of characters, say "the fox jumped over the moon@!?"

The second input: ccName, is a file containing a bunch of compression codes in the format: "t10100"

"h0010"

........

"@0100100"

etc.

Essentially what needs to be done is compression and decompression. For compression, take each letter from the inputFileName, find it in the ccName file, then match the code and add it to the outputFileName. For decompression, do the opposite.

So an example output for th@ using the codes above would be 1010000100100100 in the output file.

The methods provided are:

an array constructor and array getter and setter methods: The object of the array is CodeSet. So we have the constructor as public CodeSet(char a, String code){

We have the getter and setter methods: getCode(), getCharacter(), setCode(), setCharacter(), and a method equals(CodePair, anotherPair) which checks if two CodePairs are equal.

In addition to this we have the file methods of:

public CompressedFile(String fileName, String fileMode){

//constructor. checks if the specifed name corresponds to an existing file and if so

it opens the file

public void writeBit(char bit){

//Writes a character to the output file, where bit is the bit to write to the output file (ex: 10100 for "t")

We also have public char readBit(){

//Reads the next bit from the input file. If all the bits have been read this method returns EOF (end of file). Bit returned is first converted to a char, so this method returns a bit as either '0' or '1'.

public String readLine()

//Reads characters from the current position of the input file until the end of line

    is reached. The String read is returned. 

    returns String of characters from current position in input file until the end of line.

   returns null if there are no more characters to read from the file.

we also have public char readChar()

Reads the next character from the input file. If all the characters have been read this method returns EOF (end of file) = 0

It returns Next character from the input file .

these methods are already created^^ essentially I just need help with reading the file into the array, and then comparing that array to the input text file and writing the resulting bits to the output file.

Also, similarly, the decompression algorithm for this, which uses the methods readBit() and writeBit() I provided as well as the others.

Thanks!

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question