Results 1 to 8 of 8

Thread: Float question

  1. #1
    Lund01's Avatar
    Lund01 is offline Senior Member
    Join Date
    Sep 2010
    Location
    The Netherlands
    Posts
    149
    Rep Power
    0

    Default Float question

    I am trying a new solution on a problem i have.
    i have created a float.

    Java Code:
     
    float A = (float)1.23f; 
    float B = (float)3.11f;
    Now I have this String:
    Java Code:
     
    String string1 = "ABA";
    How do I get the the folowing output:
    String mass = 1.23 + 3.11 + 1.23 = 5.57

    Java Code:
     
    					int length = string1.length();
    					if (length >= 0) {
    						//System.out.println("test");
    					}

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    Default

    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.

  3. #3
    Lund01's Avatar
    Lund01 is offline Senior Member
    Join Date
    Sep 2010
    Location
    The Netherlands
    Posts
    149
    Rep Power
    0

    Default

    Question 1

    So I am trying this one now:

    Java 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:

    Java 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?
    Last edited by Lund01; 07-06-2011 at 08:08 PM.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    Default

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

  5. #5
    Lund01's Avatar
    Lund01 is offline Senior Member
    Join Date
    Sep 2010
    Location
    The Netherlands
    Posts
    149
    Rep Power
    0

    Default

    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.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    Default

    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.

  7. #7
    Lund01's Avatar
    Lund01 is offline Senior Member
    Join Date
    Sep 2010
    Location
    The Netherlands
    Posts
    149
    Rep Power
    0

    Default

    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.

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

    P.s. I never give up!
    (Just need more time.)

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

Similar Threads

  1. Error in float value
    By JMaste in forum New To Java
    Replies: 5
    Last Post: 07-11-2010, 05:08 PM
  2. string to float
    By Sungron in forum New To Java
    Replies: 3
    Last Post: 02-02-2010, 10:23 AM
  3. String to Float
    By durahman in forum New To Java
    Replies: 2
    Last Post: 02-12-2008, 01:17 AM
  4. Float to String
    By mew in forum New To Java
    Replies: 4
    Last Post: 12-29-2007, 06:08 PM
  5. Class float
    By Peter in forum New To Java
    Replies: 1
    Last Post: 07-08-2007, 02:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •