SlideShare a Scribd company logo
1 of 3
Download to read offline
INSTRUCTIONS For this assignment you will be generating all code on your own. You will be
submitting two primary files, and then another optionally another node file. The files you will
need to submit: - ConvertcodeToText. java - TurnTextToCode.java - Node.java - maybe
HUFFMAN CODE In the general word of computer science we use the ASCII code to turn
characters on the computer sereen into binary for storage in memory. The ASCII code was
developed in 1963 and encoded 127 "characters" into 7 bit representations. This code was then
expanded upon in 1992 with the introduction of UTF-8 encoding which allowed for 1/2/3/4 byte
representations (8/16/24/32 bit ). However the thing about these codes is that each character
requires the same amount of space, so the most common character and the least common
character require the same number of bits. However in 1952 when memory and storage space
was extremely primitive and expensive, David A. Huffman of MIT developed an encoding idea
that was based on the relative frequency of each symbol. The idea being that the most common
symbol would be given the smallest number of bits, and the least common symbol would be
given longer bits. In this way, storage space would be saved, and at the time, saving even a single
bit was valuable.
However the major downside to this, is that each and every documeat would develop its own
code, one that changed based upon the number of times a particular symbol came up. In common
English, the letter " en is the most common letter, so it would tend to have a small encoding, but
there is a novel called Gadsby that is 50,000 words and uses the letter ' e4 times. So the Huffman
Coding of this would give 'e' a abnormally large number of bits compared to normal writing.
IMPLEMENTATION DETAILS: You will be writing two programs. - Program 1 Titled -
TurnText ToCode . java This program will require a customized node class. You have the option
of adding the node class to main class, or creating a second file for it. This program will ask the
user for the name of a text file to read, and will then generate the Huffman Code for that
document, and the print off two files. - The first file will be the code itself. - The second file will
be the encoded file after applying the code to the text. - Program 2 Titled - ConvertCodeToText.
java This program will read both the code file and the encoded file, and print the decoded file to
the screen. Note that this program docsa't write any files. TURNTEXTTOCODE,JAVA To
create a Huffman code you will be mixing up and using a Priority Queue and a type of tree. You
should use the built in Java Priority Queue, but you will need to hold a custom tree in your code.
Note that due to subtle differences in execution, different versions of this program may output a
slightly different code each time you run it. That is fine, as long as when you combine the code +
huff encoding, the final output should be the same. In particular, your results my not match my
results 100%, but if it works, it is ok.
THE NODE CLASS Your node class will be the node of a tree class, but it will also contain two
pieces of data. One piece of data will be the character, and the other will be the frequency. It will
then also have a left and right child pointers. The node will also need to be comparable to be put
into the priority queue. I would suggest the following methods for your node: - A constructor
that sets both the Character and frequency - A constructor that sets the frequency and the
Character to null. - A toString0 method that prints both. - A compareT) method that compares
based on the frequency and ONLY the frequency. - An isLeaf() method to determine if the node
is a leaf or not. HOW TO CREATE A HUFFMAN CODE The instructions to create a Huffman
code are as follows: 1. Ask the user for a text file. a. Make sure the file name they type in ends
with ", txt", repeat the question if it isn't. b. So it should be " ??????. txt " with a name instead of
the question marks. 2. Open the file for reading chareter by character. a. This will require the use
of FilelnputStream instead of a normal Scanner for file reading.
FileInputStreamx=newFileInputStream(FileF); b. Then to read character by character:
&while(x.available()>)L&charc=(char)read)& c. You will have to adapt the code above to work
with a try/catch here in a way similar to how we do a seanner. d. Take each character and add it
to a list. 3. Using your list, make a map of each character and its frequency 4. Create a Java
PriorityQueue that holds your user defined Node class.
5. For each character in the map, create a node with the character and the frequency and add that
node to a priority queue. 6. While the PriorityQueue has a size greater than one: a. Remove two
nodes from the Queue. b. Create a new node with a null character, and a combined frequency of
the two nodes that were removed. c. Connect the two removed nodes to the left and right of the
new node. Onder doesn't matter: 4. So for example, if you remove [r ' / 45] and [' t ' / 55]. You
will create a new node [nu11/10e], connect the ' r ' node to left and the 't' node to right. d. Add
the newly ereated node back to the PriorityQueue. 7. Once the PriorityQueue has a single
element in it, that last node is the root of a tree that contains all the letters, and all the connecting
nodes. 8. Create a Character to String Map H2. 9. Then starting recursively at the root with an
empty string n+ : a. If the current root is null retum b. If the current root is a leaf, add the current
root character and the current string to Map H2 c. If the current root is not a leaf. $. recursively
go right with a " 0 " added to the end of the string. . recursively go left with a "I" added to the
end of the string. 10. When you are done, you should have a map with every character and the
Huffiman String that goes with it. 11. For every entry in the map print two lines to a file called
"??????. code" a. The name of the file should be the same as the input file, only with the .txt
replaced with , code. b. Line one will be the character cast into an int. So for example don't print
the character ' a ' print 65 . Don't print space, print the number 32. c. Line two will be the string
representation of the code you get from map.
12. Go back to your original list. Take every character one by one, and convert it to its
corresponding string, and print it to a file as one long continuous line. a. This output should go to
a file called "??????. huff" b. Again, this should be the same file name as the starting file, but
with . txt replaced with , huff. 13. This should complete program one.
CONVERTCODETOTEXT.JAVA 1. This program should start by asking the user for a file
name. Make sure that the file name does NOT contain any periods. Repeat until it doesn't have a
period. 2. Using the provided file name, use string techniques to create the file names that you
will use for data input. (The , huff filename and the , code file name) 3. It should then check for
the existence of both files. a. If you are missing one or both of the files, tell the user and exit. 4.
If both files exist, it should read the ". code" file and convert it into a map. a. As long as there is
a line, read the first line, and cast it back into a character. b. Read the second line which is the
string representation. c. Add the representation and the character to the map. i. Note that since
this is decode, it is easier to go string character. 5. Now open the ". huff" file and read the data
as a single large string. 6. Start with an empty string, and add a single character from the data
string to the mini string. a. If the mini-string is in the map, print out the corresponding character
and then reset the mini-string to empty. b. If the mini string is not in the map yet, add another
single character to the ministring and repeat. 7. This should decode the string/file for you.
HOW THE HUFFMAN CODE WORKS Imagine you have the following string of data:
"aaaabbbbcccddeef" First we generate a frequency map: (a,5)(b,4)(c,3)(d,2)(e,2)(f,1). Then we
create nodes of these. Then put them in a Priority Queue Take off 2 , combine them into a new
node, and reinsert. Take off 2 , combine them into a new node, and reinsert.
Now: If we let left =1 and right =0D=111F=110B=10A=01C=001E=000 and
"aaaaabbbbcccddeef" becomes 010101010110101010001001001111000000110 or something
similar. FINAL NOTES Enclosed in this program are some sample files for you to use to test
your program. PandPchapter1.txt is the first chapter of Jane Austin's Pride and Prejudice, which
is a good size data to check your work. Hamlet. txt is the entire play of Hamlet as written by W.
Shakespeare. Test this at the end to make sure your program can handle it. It might take up to a
full minute to run, but more than 60 seconds is too long. Short. txt is a very short text file to test,
but it also has an accompanying short. code and short. huff that you can use to check your
decoder. Make sure to look at short. code and short. huff in a text editor to make sure your output
matches the samples or is similar, remember, it might not be 100% the same.

More Related Content

Similar to INSTRUCTIONS For this assignment you will be generating all code on y.pdf

j001adcpresentation-2112170415 23.pdf
j001adcpresentation-2112170415      23.pdfj001adcpresentation-2112170415      23.pdf
j001adcpresentation-2112170415 23.pdfHarshSharma71048
 
Huffman Algorithm and its Application by Ekansh Agarwal
Huffman Algorithm and its Application by Ekansh AgarwalHuffman Algorithm and its Application by Ekansh Agarwal
Huffman Algorithm and its Application by Ekansh AgarwalEkansh Agarwal
 
Hello guys please make sure program runs well USING C anyth.pdf
Hello guys please make sure program runs well USING C anyth.pdfHello guys please make sure program runs well USING C anyth.pdf
Hello guys please make sure program runs well USING C anyth.pdfactioncbe1
 
Programming Languages Implementation and Design. .docx
  Programming Languages Implementation and Design. .docx  Programming Languages Implementation and Design. .docx
Programming Languages Implementation and Design. .docxaryan532920
 
Shell Scripting and Programming.pptx
Shell Scripting and Programming.pptxShell Scripting and Programming.pptx
Shell Scripting and Programming.pptxHarsha Patel
 
Shell Scripting and Programming.pptx
Shell Scripting and Programming.pptxShell Scripting and Programming.pptx
Shell Scripting and Programming.pptxHarsha Patel
 
HuffmanCoding01.doc
HuffmanCoding01.docHuffmanCoding01.doc
HuffmanCoding01.docQwertty3
 
COMP 2103X1 Assignment 2Due Thursday, January 26 by 700 PM.docx
COMP 2103X1 Assignment 2Due Thursday, January 26 by 700 PM.docxCOMP 2103X1 Assignment 2Due Thursday, January 26 by 700 PM.docx
COMP 2103X1 Assignment 2Due Thursday, January 26 by 700 PM.docxdonnajames55
 
Lewis jssap3 e_labman02
Lewis jssap3 e_labman02Lewis jssap3 e_labman02
Lewis jssap3 e_labman02auswhit
 
Hufman coding basic
Hufman coding basicHufman coding basic
Hufman coding basicradthees
 
Arrays and pointers
Arrays and pointersArrays and pointers
Arrays and pointersKevin Nguyen
 
C programming perso notes
C programming perso notesC programming perso notes
C programming perso notesMelanie Tsopze
 
Common mistakes in C programming
Common mistakes in C programmingCommon mistakes in C programming
Common mistakes in C programmingLarion
 
import java.io.BufferedReader;import java.io.BufferedWriter;.docx
import java.io.BufferedReader;import java.io.BufferedWriter;.docximport java.io.BufferedReader;import java.io.BufferedWriter;.docx
import java.io.BufferedReader;import java.io.BufferedWriter;.docxwilcockiris
 

Similar to INSTRUCTIONS For this assignment you will be generating all code on y.pdf (20)

j001adcpresentation-2112170415 23.pdf
j001adcpresentation-2112170415      23.pdfj001adcpresentation-2112170415      23.pdf
j001adcpresentation-2112170415 23.pdf
 
Huffman Algorithm and its Application by Ekansh Agarwal
Huffman Algorithm and its Application by Ekansh AgarwalHuffman Algorithm and its Application by Ekansh Agarwal
Huffman Algorithm and its Application by Ekansh Agarwal
 
Hello guys please make sure program runs well USING C anyth.pdf
Hello guys please make sure program runs well USING C anyth.pdfHello guys please make sure program runs well USING C anyth.pdf
Hello guys please make sure program runs well USING C anyth.pdf
 
Programming Languages Implementation and Design. .docx
  Programming Languages Implementation and Design. .docx  Programming Languages Implementation and Design. .docx
Programming Languages Implementation and Design. .docx
 
Shell Scripting and Programming.pptx
Shell Scripting and Programming.pptxShell Scripting and Programming.pptx
Shell Scripting and Programming.pptx
 
Shell Scripting and Programming.pptx
Shell Scripting and Programming.pptxShell Scripting and Programming.pptx
Shell Scripting and Programming.pptx
 
HuffmanCoding01.doc
HuffmanCoding01.docHuffmanCoding01.doc
HuffmanCoding01.doc
 
Huffman coding01
Huffman coding01Huffman coding01
Huffman coding01
 
COMP 2103X1 Assignment 2Due Thursday, January 26 by 700 PM.docx
COMP 2103X1 Assignment 2Due Thursday, January 26 by 700 PM.docxCOMP 2103X1 Assignment 2Due Thursday, January 26 by 700 PM.docx
COMP 2103X1 Assignment 2Due Thursday, January 26 by 700 PM.docx
 
More Pointers and Arrays
More Pointers and ArraysMore Pointers and Arrays
More Pointers and Arrays
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Lab4 scripts
Lab4 scriptsLab4 scripts
Lab4 scripts
 
Lewis jssap3 e_labman02
Lewis jssap3 e_labman02Lewis jssap3 e_labman02
Lewis jssap3 e_labman02
 
Lossless
LosslessLossless
Lossless
 
Lossless
LosslessLossless
Lossless
 
Hufman coding basic
Hufman coding basicHufman coding basic
Hufman coding basic
 
Arrays and pointers
Arrays and pointersArrays and pointers
Arrays and pointers
 
C programming perso notes
C programming perso notesC programming perso notes
C programming perso notes
 
Common mistakes in C programming
Common mistakes in C programmingCommon mistakes in C programming
Common mistakes in C programming
 
import java.io.BufferedReader;import java.io.BufferedWriter;.docx
import java.io.BufferedReader;import java.io.BufferedWriter;.docximport java.io.BufferedReader;import java.io.BufferedWriter;.docx
import java.io.BufferedReader;import java.io.BufferedWriter;.docx
 

More from adayarboot

Kelly decided to invest in Lime, Inc. common stock after reviewing.pdf
 Kelly decided to invest in Lime, Inc. common stock after reviewing.pdf Kelly decided to invest in Lime, Inc. common stock after reviewing.pdf
Kelly decided to invest in Lime, Inc. common stock after reviewing.pdfadayarboot
 
Ivanhoe Corporation is a publicly traded company and follows IFRS. On.pdf
 Ivanhoe Corporation is a publicly traded company and follows IFRS. On.pdf Ivanhoe Corporation is a publicly traded company and follows IFRS. On.pdf
Ivanhoe Corporation is a publicly traded company and follows IFRS. On.pdfadayarboot
 
Keyshawn Brown prepared and signed last years tax return on April 3 .pdf
 Keyshawn Brown prepared and signed last years tax return on April 3 .pdf Keyshawn Brown prepared and signed last years tax return on April 3 .pdf
Keyshawn Brown prepared and signed last years tax return on April 3 .pdfadayarboot
 
Kent Corp. just paid a dividend (D0) of $0.98 per share. This dividen.pdf
 Kent Corp. just paid a dividend (D0) of $0.98 per share. This dividen.pdf Kent Corp. just paid a dividend (D0) of $0.98 per share. This dividen.pdf
Kent Corp. just paid a dividend (D0) of $0.98 per share. This dividen.pdfadayarboot
 
Key Wing, Inc, prepared the fo owing bolsnce sheet st December 31, 20.pdf
 Key Wing, Inc, prepared the fo owing bolsnce sheet st December 31, 20.pdf Key Wing, Inc, prepared the fo owing bolsnce sheet st December 31, 20.pdf
Key Wing, Inc, prepared the fo owing bolsnce sheet st December 31, 20.pdfadayarboot
 
Kanha is a student at Fresno State University who recently got his fi.pdf
 Kanha is a student at Fresno State University who recently got his fi.pdf Kanha is a student at Fresno State University who recently got his fi.pdf
Kanha is a student at Fresno State University who recently got his fi.pdfadayarboot
 
JoJos portfollos return is 12 percent. She is invested in Cisco and.pdf
 JoJos portfollos return is 12 percent. She is invested in Cisco and.pdf JoJos portfollos return is 12 percent. She is invested in Cisco and.pdf
JoJos portfollos return is 12 percent. She is invested in Cisco and.pdfadayarboot
 
Jaynes. Inc; acquired all of Aaron Co. s common stock on January 1, .pdf
 Jaynes. Inc; acquired all of Aaron Co. s common stock on January 1, .pdf Jaynes. Inc; acquired all of Aaron Co. s common stock on January 1, .pdf
Jaynes. Inc; acquired all of Aaron Co. s common stock on January 1, .pdfadayarboot
 
Jessica satisfies exponential discounting with u=x2 and =0.9. She fac.pdf
 Jessica satisfies exponential discounting with u=x2 and =0.9. She fac.pdf Jessica satisfies exponential discounting with u=x2 and =0.9. She fac.pdf
Jessica satisfies exponential discounting with u=x2 and =0.9. She fac.pdfadayarboot
 
It was 720 a.m. when Mohammed arrived at the office. He was early be.pdf
 It was 720 a.m. when Mohammed arrived at the office. He was early be.pdf It was 720 a.m. when Mohammed arrived at the office. He was early be.pdf
It was 720 a.m. when Mohammed arrived at the office. He was early be.pdfadayarboot
 
irt essay. Write two short paragraphs about photorespiration. In th.pdf
 irt essay. Write two short paragraphs about photorespiration. In th.pdf irt essay. Write two short paragraphs about photorespiration. In th.pdf
irt essay. Write two short paragraphs about photorespiration. In th.pdfadayarboot
 
Inventory information for Part 311 of Blue Corp. discloses the follow.pdf
 Inventory information for Part 311 of Blue Corp. discloses the follow.pdf Inventory information for Part 311 of Blue Corp. discloses the follow.pdf
Inventory information for Part 311 of Blue Corp. discloses the follow.pdfadayarboot
 
Intro Terence Terraforming Inc. has a capital structure of 24 debt a.pdf
 Intro Terence Terraforming Inc. has a capital structure of 24 debt a.pdf Intro Terence Terraforming Inc. has a capital structure of 24 debt a.pdf
Intro Terence Terraforming Inc. has a capital structure of 24 debt a.pdfadayarboot
 
In reponse to much criticism about the reliance on GDP measures for p.pdf
 In reponse to much criticism about the reliance on GDP measures for p.pdf In reponse to much criticism about the reliance on GDP measures for p.pdf
In reponse to much criticism about the reliance on GDP measures for p.pdfadayarboot
 
Instructions Construct the probability distribution based on the giv.pdf
 Instructions Construct the probability distribution based on the giv.pdf Instructions Construct the probability distribution based on the giv.pdf
Instructions Construct the probability distribution based on the giv.pdfadayarboot
 
Instructions Complete the following cxercises that have been adapted.pdf
 Instructions Complete the following cxercises that have been adapted.pdf Instructions Complete the following cxercises that have been adapted.pdf
Instructions Complete the following cxercises that have been adapted.pdfadayarboot
 
Insert the correct words into the blanks in the text. When insertin.pdf
 Insert the correct words into the blanks in the text. When insertin.pdf Insert the correct words into the blanks in the text. When insertin.pdf
Insert the correct words into the blanks in the text. When insertin.pdfadayarboot
 
Ingals Construction Associates accepted a contract to build an office.pdf
 Ingals Construction Associates accepted a contract to build an office.pdf Ingals Construction Associates accepted a contract to build an office.pdf
Ingals Construction Associates accepted a contract to build an office.pdfadayarboot
 
Initially Apple products like the Mac Computer, iPod, iPad and iPhone.pdf
 Initially Apple products like the Mac Computer, iPod, iPad and iPhone.pdf Initially Apple products like the Mac Computer, iPod, iPad and iPhone.pdf
Initially Apple products like the Mac Computer, iPod, iPad and iPhone.pdfadayarboot
 
Independent Assortment Two genes, Dumb (d) and Anxious (a), are reces.pdf
 Independent Assortment Two genes, Dumb (d) and Anxious (a), are reces.pdf Independent Assortment Two genes, Dumb (d) and Anxious (a), are reces.pdf
Independent Assortment Two genes, Dumb (d) and Anxious (a), are reces.pdfadayarboot
 

More from adayarboot (20)

Kelly decided to invest in Lime, Inc. common stock after reviewing.pdf
 Kelly decided to invest in Lime, Inc. common stock after reviewing.pdf Kelly decided to invest in Lime, Inc. common stock after reviewing.pdf
Kelly decided to invest in Lime, Inc. common stock after reviewing.pdf
 
Ivanhoe Corporation is a publicly traded company and follows IFRS. On.pdf
 Ivanhoe Corporation is a publicly traded company and follows IFRS. On.pdf Ivanhoe Corporation is a publicly traded company and follows IFRS. On.pdf
Ivanhoe Corporation is a publicly traded company and follows IFRS. On.pdf
 
Keyshawn Brown prepared and signed last years tax return on April 3 .pdf
 Keyshawn Brown prepared and signed last years tax return on April 3 .pdf Keyshawn Brown prepared and signed last years tax return on April 3 .pdf
Keyshawn Brown prepared and signed last years tax return on April 3 .pdf
 
Kent Corp. just paid a dividend (D0) of $0.98 per share. This dividen.pdf
 Kent Corp. just paid a dividend (D0) of $0.98 per share. This dividen.pdf Kent Corp. just paid a dividend (D0) of $0.98 per share. This dividen.pdf
Kent Corp. just paid a dividend (D0) of $0.98 per share. This dividen.pdf
 
Key Wing, Inc, prepared the fo owing bolsnce sheet st December 31, 20.pdf
 Key Wing, Inc, prepared the fo owing bolsnce sheet st December 31, 20.pdf Key Wing, Inc, prepared the fo owing bolsnce sheet st December 31, 20.pdf
Key Wing, Inc, prepared the fo owing bolsnce sheet st December 31, 20.pdf
 
Kanha is a student at Fresno State University who recently got his fi.pdf
 Kanha is a student at Fresno State University who recently got his fi.pdf Kanha is a student at Fresno State University who recently got his fi.pdf
Kanha is a student at Fresno State University who recently got his fi.pdf
 
JoJos portfollos return is 12 percent. She is invested in Cisco and.pdf
 JoJos portfollos return is 12 percent. She is invested in Cisco and.pdf JoJos portfollos return is 12 percent. She is invested in Cisco and.pdf
JoJos portfollos return is 12 percent. She is invested in Cisco and.pdf
 
Jaynes. Inc; acquired all of Aaron Co. s common stock on January 1, .pdf
 Jaynes. Inc; acquired all of Aaron Co. s common stock on January 1, .pdf Jaynes. Inc; acquired all of Aaron Co. s common stock on January 1, .pdf
Jaynes. Inc; acquired all of Aaron Co. s common stock on January 1, .pdf
 
Jessica satisfies exponential discounting with u=x2 and =0.9. She fac.pdf
 Jessica satisfies exponential discounting with u=x2 and =0.9. She fac.pdf Jessica satisfies exponential discounting with u=x2 and =0.9. She fac.pdf
Jessica satisfies exponential discounting with u=x2 and =0.9. She fac.pdf
 
It was 720 a.m. when Mohammed arrived at the office. He was early be.pdf
 It was 720 a.m. when Mohammed arrived at the office. He was early be.pdf It was 720 a.m. when Mohammed arrived at the office. He was early be.pdf
It was 720 a.m. when Mohammed arrived at the office. He was early be.pdf
 
irt essay. Write two short paragraphs about photorespiration. In th.pdf
 irt essay. Write two short paragraphs about photorespiration. In th.pdf irt essay. Write two short paragraphs about photorespiration. In th.pdf
irt essay. Write two short paragraphs about photorespiration. In th.pdf
 
Inventory information for Part 311 of Blue Corp. discloses the follow.pdf
 Inventory information for Part 311 of Blue Corp. discloses the follow.pdf Inventory information for Part 311 of Blue Corp. discloses the follow.pdf
Inventory information for Part 311 of Blue Corp. discloses the follow.pdf
 
Intro Terence Terraforming Inc. has a capital structure of 24 debt a.pdf
 Intro Terence Terraforming Inc. has a capital structure of 24 debt a.pdf Intro Terence Terraforming Inc. has a capital structure of 24 debt a.pdf
Intro Terence Terraforming Inc. has a capital structure of 24 debt a.pdf
 
In reponse to much criticism about the reliance on GDP measures for p.pdf
 In reponse to much criticism about the reliance on GDP measures for p.pdf In reponse to much criticism about the reliance on GDP measures for p.pdf
In reponse to much criticism about the reliance on GDP measures for p.pdf
 
Instructions Construct the probability distribution based on the giv.pdf
 Instructions Construct the probability distribution based on the giv.pdf Instructions Construct the probability distribution based on the giv.pdf
Instructions Construct the probability distribution based on the giv.pdf
 
Instructions Complete the following cxercises that have been adapted.pdf
 Instructions Complete the following cxercises that have been adapted.pdf Instructions Complete the following cxercises that have been adapted.pdf
Instructions Complete the following cxercises that have been adapted.pdf
 
Insert the correct words into the blanks in the text. When insertin.pdf
 Insert the correct words into the blanks in the text. When insertin.pdf Insert the correct words into the blanks in the text. When insertin.pdf
Insert the correct words into the blanks in the text. When insertin.pdf
 
Ingals Construction Associates accepted a contract to build an office.pdf
 Ingals Construction Associates accepted a contract to build an office.pdf Ingals Construction Associates accepted a contract to build an office.pdf
Ingals Construction Associates accepted a contract to build an office.pdf
 
Initially Apple products like the Mac Computer, iPod, iPad and iPhone.pdf
 Initially Apple products like the Mac Computer, iPod, iPad and iPhone.pdf Initially Apple products like the Mac Computer, iPod, iPad and iPhone.pdf
Initially Apple products like the Mac Computer, iPod, iPad and iPhone.pdf
 
Independent Assortment Two genes, Dumb (d) and Anxious (a), are reces.pdf
 Independent Assortment Two genes, Dumb (d) and Anxious (a), are reces.pdf Independent Assortment Two genes, Dumb (d) and Anxious (a), are reces.pdf
Independent Assortment Two genes, Dumb (d) and Anxious (a), are reces.pdf
 

Recently uploaded

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 

Recently uploaded (20)

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 

INSTRUCTIONS For this assignment you will be generating all code on y.pdf

  • 1. INSTRUCTIONS For this assignment you will be generating all code on your own. You will be submitting two primary files, and then another optionally another node file. The files you will need to submit: - ConvertcodeToText. java - TurnTextToCode.java - Node.java - maybe HUFFMAN CODE In the general word of computer science we use the ASCII code to turn characters on the computer sereen into binary for storage in memory. The ASCII code was developed in 1963 and encoded 127 "characters" into 7 bit representations. This code was then expanded upon in 1992 with the introduction of UTF-8 encoding which allowed for 1/2/3/4 byte representations (8/16/24/32 bit ). However the thing about these codes is that each character requires the same amount of space, so the most common character and the least common character require the same number of bits. However in 1952 when memory and storage space was extremely primitive and expensive, David A. Huffman of MIT developed an encoding idea that was based on the relative frequency of each symbol. The idea being that the most common symbol would be given the smallest number of bits, and the least common symbol would be given longer bits. In this way, storage space would be saved, and at the time, saving even a single bit was valuable. However the major downside to this, is that each and every documeat would develop its own code, one that changed based upon the number of times a particular symbol came up. In common English, the letter " en is the most common letter, so it would tend to have a small encoding, but there is a novel called Gadsby that is 50,000 words and uses the letter ' e4 times. So the Huffman Coding of this would give 'e' a abnormally large number of bits compared to normal writing. IMPLEMENTATION DETAILS: You will be writing two programs. - Program 1 Titled - TurnText ToCode . java This program will require a customized node class. You have the option of adding the node class to main class, or creating a second file for it. This program will ask the user for the name of a text file to read, and will then generate the Huffman Code for that document, and the print off two files. - The first file will be the code itself. - The second file will be the encoded file after applying the code to the text. - Program 2 Titled - ConvertCodeToText. java This program will read both the code file and the encoded file, and print the decoded file to the screen. Note that this program docsa't write any files. TURNTEXTTOCODE,JAVA To create a Huffman code you will be mixing up and using a Priority Queue and a type of tree. You should use the built in Java Priority Queue, but you will need to hold a custom tree in your code. Note that due to subtle differences in execution, different versions of this program may output a slightly different code each time you run it. That is fine, as long as when you combine the code + huff encoding, the final output should be the same. In particular, your results my not match my results 100%, but if it works, it is ok.
  • 2. THE NODE CLASS Your node class will be the node of a tree class, but it will also contain two pieces of data. One piece of data will be the character, and the other will be the frequency. It will then also have a left and right child pointers. The node will also need to be comparable to be put into the priority queue. I would suggest the following methods for your node: - A constructor that sets both the Character and frequency - A constructor that sets the frequency and the Character to null. - A toString0 method that prints both. - A compareT) method that compares based on the frequency and ONLY the frequency. - An isLeaf() method to determine if the node is a leaf or not. HOW TO CREATE A HUFFMAN CODE The instructions to create a Huffman code are as follows: 1. Ask the user for a text file. a. Make sure the file name they type in ends with ", txt", repeat the question if it isn't. b. So it should be " ??????. txt " with a name instead of the question marks. 2. Open the file for reading chareter by character. a. This will require the use of FilelnputStream instead of a normal Scanner for file reading. FileInputStreamx=newFileInputStream(FileF); b. Then to read character by character: &while(x.available()>)L&charc=(char)read)& c. You will have to adapt the code above to work with a try/catch here in a way similar to how we do a seanner. d. Take each character and add it to a list. 3. Using your list, make a map of each character and its frequency 4. Create a Java PriorityQueue that holds your user defined Node class. 5. For each character in the map, create a node with the character and the frequency and add that node to a priority queue. 6. While the PriorityQueue has a size greater than one: a. Remove two nodes from the Queue. b. Create a new node with a null character, and a combined frequency of the two nodes that were removed. c. Connect the two removed nodes to the left and right of the new node. Onder doesn't matter: 4. So for example, if you remove [r ' / 45] and [' t ' / 55]. You will create a new node [nu11/10e], connect the ' r ' node to left and the 't' node to right. d. Add the newly ereated node back to the PriorityQueue. 7. Once the PriorityQueue has a single element in it, that last node is the root of a tree that contains all the letters, and all the connecting nodes. 8. Create a Character to String Map H2. 9. Then starting recursively at the root with an empty string n+ : a. If the current root is null retum b. If the current root is a leaf, add the current root character and the current string to Map H2 c. If the current root is not a leaf. $. recursively go right with a " 0 " added to the end of the string. . recursively go left with a "I" added to the end of the string. 10. When you are done, you should have a map with every character and the Huffiman String that goes with it. 11. For every entry in the map print two lines to a file called "??????. code" a. The name of the file should be the same as the input file, only with the .txt replaced with , code. b. Line one will be the character cast into an int. So for example don't print the character ' a ' print 65 . Don't print space, print the number 32. c. Line two will be the string representation of the code you get from map.
  • 3. 12. Go back to your original list. Take every character one by one, and convert it to its corresponding string, and print it to a file as one long continuous line. a. This output should go to a file called "??????. huff" b. Again, this should be the same file name as the starting file, but with . txt replaced with , huff. 13. This should complete program one. CONVERTCODETOTEXT.JAVA 1. This program should start by asking the user for a file name. Make sure that the file name does NOT contain any periods. Repeat until it doesn't have a period. 2. Using the provided file name, use string techniques to create the file names that you will use for data input. (The , huff filename and the , code file name) 3. It should then check for the existence of both files. a. If you are missing one or both of the files, tell the user and exit. 4. If both files exist, it should read the ". code" file and convert it into a map. a. As long as there is a line, read the first line, and cast it back into a character. b. Read the second line which is the string representation. c. Add the representation and the character to the map. i. Note that since this is decode, it is easier to go string character. 5. Now open the ". huff" file and read the data as a single large string. 6. Start with an empty string, and add a single character from the data string to the mini string. a. If the mini-string is in the map, print out the corresponding character and then reset the mini-string to empty. b. If the mini string is not in the map yet, add another single character to the ministring and repeat. 7. This should decode the string/file for you. HOW THE HUFFMAN CODE WORKS Imagine you have the following string of data: "aaaabbbbcccddeef" First we generate a frequency map: (a,5)(b,4)(c,3)(d,2)(e,2)(f,1). Then we create nodes of these. Then put them in a Priority Queue Take off 2 , combine them into a new node, and reinsert. Take off 2 , combine them into a new node, and reinsert. Now: If we let left =1 and right =0D=111F=110B=10A=01C=001E=000 and "aaaaabbbbcccddeef" becomes 010101010110101010001001001111000000110 or something similar. FINAL NOTES Enclosed in this program are some sample files for you to use to test your program. PandPchapter1.txt is the first chapter of Jane Austin's Pride and Prejudice, which is a good size data to check your work. Hamlet. txt is the entire play of Hamlet as written by W. Shakespeare. Test this at the end to make sure your program can handle it. It might take up to a full minute to run, but more than 60 seconds is too long. Short. txt is a very short text file to test, but it also has an accompanying short. code and short. huff that you can use to check your decoder. Make sure to look at short. code and short. huff in a text editor to make sure your output matches the samples or is similar, remember, it might not be 100% the same.