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
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.
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?
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.
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.
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.