File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Morse code conversion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Morse code conversion" Watch "Morse code conversion" New topic
Author

Morse code conversion

Clay Adkerson
Greenhorn

Joined: Mar 16, 2005
Posts: 27
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
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
You could use a HashMap that contains letters and code.
Clay Adkerson
Greenhorn

Joined: Mar 16, 2005
Posts: 27
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

Joined: Feb 07, 2005
Posts: 2367
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

Joined: Mar 16, 2005
Posts: 27
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

Joined: Mar 16, 2005
Posts: 27
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?
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
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.


42
Clay Adkerson
Greenhorn

Joined: Mar 16, 2005
Posts: 27
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.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30116
    
150

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
 
subject: Morse code conversion
 
Similar Threads
Help with english to morse code program, I have no idea what I'm doing
clearing a text field for new text
converting morse code to english
morse code converters
labels in java gui components