• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

Hashmap/Binary Tree

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a java program that should import and read a textfile containing lines of morse code as well as english phrases. The program should use a binary tree and hashmap to decode both the morse and the english phrases. I have built my binary tree for the morse that reads another text file (that contains the alphabet and their coordinating morse code values). How could I go about adding a hashmao to my code to read the english part of the textfile? I am stuck!
 
Saloon Keeper
Posts: 12493
269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why have you settled on these data structure before knowing that they are the right solution? Is this an exercise?

What do you mean by "decode the English prases"? What is the end goal?
 
Marshal
Posts: 71070
292
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Why have you settled on these data structure . . .

She hasn't. She has been told to use them as an exercise in using those data structures. I think, “decode,” should read, “encode.”
ER: You are asking the wrong question

How could I go about adding a hashmao to my code to read the english part of the textfile?

You don't use Maps to read text files. You use Scanners or Buffered Readers or similar. You have confused yourself because you haven't broken the task down enough. Reading the different files is two separate tasks distinct from using maps or trees.
By the way: What are you going to do when your text contains spaces? How are you going to distinguish "." (=Morse code for e) from "." (=common punctuation mark)? Do you have the Morse Code and the letters in different columns? That could distinguish them, and I would use a Scanner to read such a file.
Have you got a MorseCodeCharacter (or similar) class? I don't know whether such a class would make it easier or harder to do this exercise.
 
There are 29 Knuts in one Sickle, and 17 Sickles make up a Galleon. 42 tiny ads in a knut:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic