# Float question

• 07-06-2011, 06:26 PM
Lund01
Float question
I am trying a new solution on a problem i have.
i have created a float.

Code:

``` float A = (float)1.23f; float B = (float)3.11f;```
Now I have this String:
Code:

``` String string1 = "ABA";```
How do I get the the folowing output:
String mass = 1.23 + 3.11 + 1.23 = 5.57

Code:

```                                         int length = string1.length();                                         if (length >= 0) {                                                 //System.out.println("test");                                         }```
• 07-06-2011, 06:39 PM
Norm
It appears that you want to scan the String: "ABA" and use the letter to get a value.
A Map will allow you to do this.
For the key = the letter, the value is the class object (your class) with a String representing the value and the numberic value.
Get the letters one by one and get the object from the Map. Use the String part to build the mass String and use the numberic value to do the summing.
• 07-06-2011, 07:55 PM
Lund01
Question 1

So I am trying this one now:

Code:

``` Map <String, Integer> x = new LinkedHashMap <String, Integer>(16, 0.75f, true); x.put("A", 1);```
But how do i make it something wit a 1.23?

My 2nd question:

Code:

```                                         for (int i = 0; i < string1.length(); i++) {                                                 String ss = string1.substring(i, i +1);                                                 System.out.println(x.get(ss).intValue());                                         }```
But then I still have only loose values.
How do I count then with each other?
• 07-06-2011, 07:59 PM
Norm
What do you want done with the 1.23?
I assume that is the contents of a double or float variable. Or is it a String? "1.23"
There are wrapper classes for float(Float) and double(Double) just like int(Integer).
• 07-06-2011, 08:21 PM
Lund01
The only thing I need is to calculate a peptide mass from each peptide.
And a peptide looks like a string of letters.
So if you would have: ABA, I would like to have as output 5.57.

Input: ABA
Output 5.57.
That is all. :)-:
• 07-06-2011, 08:24 PM
Norm
You need a design for your application. You have input data and a desired result.
You need to connect the two. I suggested an approach. Have you given up on it already?

There is nothing in java to handle peptide mass.
• 07-06-2011, 08:34 PM
Lund01
To be honest I am working on this already a few weeks, and i am nearly there (for the whole program).
The problem is that there is nowhere softare availeble to do this.
If we need to do this manually it will take ages, so it is not an option. :(shake):

Lets say we only need to invent the wheel one time.
As this program is gonna be "free to download to everyone". :8):

P.s. I never give up!
(Just need more time.)
• 07-06-2011, 08:36 PM
Norm
Ok. Keep going.
Come back if you have any more problems.