I have got the same error: ProteinSequence.java:60: incompatible types
found : java.lang.String
required: java.lang.Character
letter = m.get(letters[i]);
^
Any help will be appriciated

Look at the error output. It's telling you that "letter = m.get(letters[i]);" is your error. Think about it. map is a HashMap<Character, String>. The format is HashMap<Key, Value>. So when you call hashmap.get(k), the "k" is a key and it returns a value. so you pass get a Character and it returns a String. Now look at that line again and ask yourself, "Is letter a String or a Character? What is the return type of get? Do they match?"

Re: incompatible types

Posted 10 April 2007 - 08:24 AM

Hi, alcdotcom
Thanks a lot. That was a great advise
BUT another problem came up.
I do not understand why I get only one value (the last one in the String[]fulnames each time I call the method in the main. For example the value for the key'V' or key 'G' is always the same- "stop".
Is there something wrong in the way I put the keys and the values in the map.
I hope somebody can help
This is the code again:

Re: incompatible types

Posted 10 April 2007 - 09:27 AM

stanka, on 10 Apr, 2007 - 08:24 AM, said:

Hi, alcdotcom
Thanks a lot. That was a great advise
BUT another problem came up.
I do not understand why I get only one value (the last one in the String[]fulnames each time I call the method in the main. For example the value for the key'V' or key 'G' is always the same- "stop".
Is there something wrong in the way I put the keys and the values in the map.
I hope somebody can help
This is the code again:

Ok, for starters, I think you'd be able to see the problem a lot more clearly if you made your code a little more readable. Also, when you're posting your code, put them in code tags. Look at my version:

It's the same thing, only much more readable. Look at your second loop. It loops through both arrays, assigning letter a value and fullName a value during each iteration. Ask yourself what purpose does it serve? What can you change/remove that would make this method do what you want?

Re: incompatible types

Posted 10 April 2007 - 11:31 AM

Hi
I am afarid that I need more hints?

alcdotcom, on 10 Apr, 2007 - 09:27 AM, said:

stanka, on 10 Apr, 2007 - 08:24 AM, said:

Hi, alcdotcom
Thanks a lot. That was a great advise
BUT another problem came up.
I do not understand why I get only one value (the last one in the String[]fulnames each time I call the method in the main. For example the value for the key'V' or key 'G' is always the same- "stop".
Is there something wrong in the way I put the keys and the values in the map.
I hope somebody can help
This is the code again:

Ok, for starters, I think you'd be able to see the problem a lot more clearly if you made your code a little more readable. Also, when you're posting your code, put them in code tags. Look at my version:

It's the same thing, only much more readable. Look at your second loop. It loops through both arrays, assigning letter a value and fullName a value during each iteration. Ask yourself what purpose does it serve? What can you change/remove that would make this method do what you want?

So the loop continues until the loop gets to the end of the array and then your method returns fullName. You get it now?

Thanks,
I see. How, then I can assign a value to letter, which is an element from the Char[]letters array. If I call m.getKey(i) I have got an error : Cannot find symbol
cannot find symbol
symbol : method getKey()
location: interface java.util.Map<java.lang.Character,java.lang.String>
{letter = m.getKey();

Re: incompatible types

Posted 11 April 2007 - 04:16 AM

I added the code box for you. The way you do it is, drag your mouse to select/highlight all of your code and then click the button with the "#." You should read the BB Code help page. Click the link that says "BB Code Help" below the smileys.

Ok. I'm going to give you some advice on this method. It can be really really simple. First, you create two arrays every time the method is called. Since these arrays don't change then it would be better to declare and create them in your class constructor or in the beginning of your class and make them final.

Now that these are declared outside of your method they are only declared and created once, instead of every time the method is called. You can also access them from within the method because they have global scope.

Next, consider the loop that fills your map. That happens every time the method is called too. Since it's the same every time, why not put it in the constructor? So, now we have:

Above I have declared the map, "m", with the arrays, so it also has global scope. In the constructor, I've initialized m and also filled it with the data from the arrays. notice the indentation I've used for the loop. Isn't that easier to read than putting it on one line? So, after breaking all of this unnecessary stuff out of your getFullName method it leaves this:

I want to help you with this, but I also want you to figure it out for yourself. So, think about this. You have a Character as an input and you need a String as an output. You have a map which takes a Character as an input and returns a String as an output. If I wanted to know the String value of Character key 'G' in m, I would call m.get('G');. That's it. Now, look at your method. It's doing too much and it's also doing the wrong things. I recommend thinking about what I've said and then starting over with that method. Just delete everything in the method and then think about how you can use the functionality that is built in to the Map to make this method return the right value. You might even think about the method as a wrapper for your Map, if that makes sense.

I am still having trobles to understand how to define the parameter letter in the code.
I read a lot of literature on maps but... I feel completely stuck.
Please help!

alcdotcom, on 11 Apr, 2007 - 04:16 AM, said:

I added the code box for you. The way you do it is, drag your mouse to select/highlight all of your code and then click the button with the "#." You should read the BB Code help page. Click the link that says "BB Code Help" below the smileys.

Ok. I'm going to give you some advice on this method. It can be really really simple. First, you create two arrays every time the method is called. Since these arrays don't change then it would be better to declare and create them in your class constructor or in the beginning of your class and make them final.

Now that these are declared outside of your method they are only declared and created once, instead of every time the method is called. You can also access them from within the method because they have global scope.

Next, consider the loop that fills your map. That happens every time the method is called too. Since it's the same every time, why not put it in the constructor? So, now we have:

Above I have declared the map, "m", with the arrays, so it also has global scope. In the constructor, I've initialized m and also filled it with the data from the arrays. notice the indentation I've used for the loop. Isn't that easier to read than putting it on one line? So, after breaking all of this unnecessary stuff out of your getFullName method it leaves this:

I want to help you with this, but I also want you to figure it out for yourself. So, think about this. You have a Character as an input and you need a String as an output. You have a map which takes a Character as an input and returns a String as an output. If I wanted to know the String value of Character key 'G' in m, I would call m.get('G');. That's it. Now, look at your method. It's doing too much and it's also doing the wrong things. I recommend thinking about what I've said and then starting over with that method. Just delete everything in the method and then think about how you can use the functionality that is built in to the Map to make this method return the right value. You might even think about the method as a wrapper for your Map, if that makes sense.

I still do not understand how to define the variable letter in the method. How to retrieve the key from the map.

alcdotcom, on 11 Apr, 2007 - 04:16 AM, said:

I added the code box for you. The way you do it is, drag your mouse to select/highlight all of your code and then click the button with the "#." You should read the BB Code help page. Click the link that says "BB Code Help" below the smileys.

Ok. I'm going to give you some advice on this method. It can be really really simple. First, you create two arrays every time the method is called. Since these arrays don't change then it would be better to declare and create them in your class constructor or in the beginning of your class and make them final.

Now that these are declared outside of your method they are only declared and created once, instead of every time the method is called. You can also access them from within the method because they have global scope.

Next, consider the loop that fills your map. That happens every time the method is called too. Since it's the same every time, why not put it in the constructor? So, now we have:

Above I have declared the map, "m", with the arrays, so it also has global scope. In the constructor, I've initialized m and also filled it with the data from the arrays. notice the indentation I've used for the loop. Isn't that easier to read than putting it on one line? So, after breaking all of this unnecessary stuff out of your getFullName method it leaves this:

I want to help you with this, but I also want you to figure it out for yourself. So, think about this. You have a Character as an input and you need a String as an output. You have a map which takes a Character as an input and returns a String as an output. If I wanted to know the String value of Character key 'G' in m, I would call m.get('G');. That's it. Now, look at your method. It's doing too much and it's also doing the wrong things. I recommend thinking about what I've said and then starting over with that method. Just delete everything in the method and then think about how you can use the functionality that is built in to the Map to make this method return the right value. You might even think about the method as a wrapper for your Map, if that makes sense.