• 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

Morse code conversion

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For class me have to make a program that will convert text to morsecode and vice versa. I see how to do it but i can't figure it up in code. What i have so far is a 3 classes: Encode(text to morse), Decode(Morse to Text), and Converter which contains the Main method and takes the input. What i did was make a file that contatins the ABCs and 0-9 and put the conversions next to them seperated by a space. What i need to do is get the input, convert each letter, and then put them back. Im not sure what to use to do this. If anyone could give me some ways to do it that would help greatly. Im not asking for the whole code, just a good starting point.
-Clay
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could use a HashMap that contains letters and code.
 
Clay Adkerson
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont know what that is but i read some of the APi on Strings and i used toCharArray which will work with Text to Morse but Morse to Text i will need something different but one thing at a time.
 
Keith Lynn
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A Hashmap is a structure that maps keys to values. So you could have one map where the keys are the characters, and the values are the codes, and another where the keys are the codes, and the values are the letters.
 
Clay Adkerson
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds exactly what i needed. I'll look into it. Thanks for the help so far. Ill post here when i get a basic structure down.
 
Clay Adkerson
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A question with HashMaps. It compiles fine pretty much but it tells me run with the compiler with -Xlint(im using JCreator) so i do it and it gives me a warning for every key that i added. It says: [unchecked] unchecked call to put(k,v) as a member of the raw type java.util.HashMap. What does that mean and should i just ignore it?
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read up on generics. You probably used code like

Under java 1.5/5.0/Tiger this should be coded as


The older code construct is still correct and will work fine, but the compiler gives you a friendly warning that it can't do compile-time type checking on values entered into and retrieved from the HashMap.
 
Clay Adkerson
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, i got text to morse done. Now for morse to text. Is there a way i can create a new HashMap that switches the keys and values of the other one? i really don't want to type in all that stuff again.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Clay,
You can write a loop to do it. The map.keySet() method will give you a list of all the keys in your original map. When looping through that set, you can get the value (since you have the key) and put them into a new map inverting the key and the value.
reply
    Bookmark Topic Watch Topic
  • New Topic