• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

converting morse code to english

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to set up a morse code-english converter by prompting the user for morse-->english translation or english--> morse translation, prompting the user to enter the text to be translated, and then finally translating it. So far, I've been able to do english-->morse code translations because that just involves encoding each individual letter. I'm having trouble with morse-->english translations though because that doesn't just involve decoding each individual character. The problem I'm having is I don't want the program to convert each individual dash and period to a letter, but rather a string of dashes and periods to a letter (..-. = f). I also want "|" to separate each word in morse code. For example, if morse code input is "-- -.-- | -. .- -- ." then translated output should be "my name". I implemented this successfully in the stringToMorse() method, but I don't know how I would do it in the stringToEnglish() method. Any ideas are appreciated.

 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all you probably can implement the conversion from letter to morse-code more efficient with an array or Map instead of those if-statements.

For stringToEnglish: split the morse-code on "|" and do the opposite of creating morse-code based on the letter.
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
. . . and check whether your Morse code is consistent. You have ".- " for a, with a space in, and no spaces for any other letters. That will cause errors.
 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Khair: You can do something like this:

Create a database /look up table sort of thing for morse<->english
say something like this.

Take the input as a string.
use a counter to count '|' from the current position, make a substring
search for this substring in morse code array,once found, printout the character from corresponding english array or put that in string.
in this way, you can eliminate the if statements for both types of conversions.
 
Campbell Ritchie
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As suggested earlier, a Map is a far better solution.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic