Results 1 to 7 of 7
  1. #1
    noviceJava is offline Member
    Join Date
    Apr 2012
    Posts
    16
    Rep Power
    0

    Default trying to get data from an object array

    I have this array:

    ID r1 r2 azm1 r1 r2 azm1 r1 r2 azm1
    H 50 60 12 40 50 24 20 50 99

    now to read this array I need to read in the ID r1 r2 azm1 that is my first obstacle? second obstacle is to send this data to another function?

    Java Code:
    public class RHOState
    private static final LineParserType[] TYPE_LIST = {LineParser.STRING,
                                                         LineParser.INTEGER,
                                                         LineParser.INTEGER,
                                                         LineParser.INTEGER};
    /**
       * Creates a RHO shapeType field.
       */
      public RHO_State() {}
    
    protected void readRhoLine(String line)
          throws SiteErrorException {
          Object[] lineContents = LineParser.parseLine(line, TYPE_LIST);
           int a1 = 0;
          while ( lineContents != null ) {
              String id = ((String)lineContents[0]).toUpperCase(); 
              int r1= ((Integer)lineContents[1]).intValue();
              int r2= ((Integer)lineContents[2]).intValue();
              int a2 = ((Integer)lineContents[3]).intValue();
              try {
              Sensor sensor = (Sensor)source;
              sensor.addRHO(id, r1, r2, a1, a2);
            }
              catch (InvalidDataException e) {
                throw new SiteErrorException(e.getMessage());
              }
          }
        }
      }

    so I beleive that the object array is setup to read the file
    but when I call addRHO it needs to be called like this

    id r1 r2 a1 a2

    but the a1 the first time thru needs to be '0' and a2 would be 12
    then the second time thru a1 needs to equal 12 and a2 needs to equal 24
    then third time thru a1 = 24 the a2 = 99
    not sure how that code needs to be written?

    any help thanks
    Last edited by noviceJava; 03-03-2016 at 04:30 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: trying to get data from an object array

    I have this array:
    Can you explain what are the data types of the elements in the array? Are they Strings?
    What you posted looks like a String with characters: letters, spaces and numeric digits. Why are you calling it an array?
    I need to read in the ID r1 r2 azm1
    That depends on what type of array it is.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    noviceJava is offline Member
    Join Date
    Apr 2012
    Posts
    16
    Rep Power
    0

    Default Re: trying to get data from an object array

    Quote Originally Posted by Norm View Post
    Can you explain what are the data types of the elements in the array? Are they Strings?
    What you posted looks like a String with characters: letters, spaces and numeric digits. Why are you calling it an array?

    That depends on what type of array it is.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    sorry not sure how to use code tags?

    sorry to call it an array it is a list of strings. (this is correct String with characters: letters, spaces and numeric digits.) i called it an array of objects because I thougt it was called that

  4. #4
    noviceJava is offline Member
    Join Date
    Apr 2012
    Posts
    16
    Rep Power
    0

    Default Re: trying to get data from an object array

    I think i figured out the code tag thing

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: trying to get data from an object array

    Ok, can you explain what your problem is now?
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    noviceJava is offline Member
    Join Date
    Apr 2012
    Posts
    16
    Rep Power
    0

    Default Re: trying to get data from an object array

    Quote Originally Posted by noviceJava View Post
    I think i figured out the code tag thing
    ok


    For a response I am trying to read in that String but I need to get each group separatly like group1 = 40 50 12 group2 = 40 50 23 etc.


    then I want to do the following

    the number 12 in the string is the second number I want to send to another method the first number will be 0(zero)

    so for addRHO(40 50 0 12) then the second time thru would be addRHO(50 60 12 23) where the new first azimuth will now be what the second azimuth was in the first call to method addRHO

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: trying to get data from an object array

    Are group1 and group2 String variables? What does the input look like that you want to split between those two variables?
    For example if the input String was: "40 50 12 40 50 23" the if you could find the location the second "40" you could use the substring method to retrieve the 2 desired Strings from the input String.

    number 12 in the string is the second number
    Please explain that. It looks like the third number to me after 40 and 50.

    so for addRHO(40 50 0 12) then the second time thru would be addRHO(50 60 12 23) where the new first azimuth will now be what the second azimuth was in the first call to method addRHO
    I have no idea what you mean by that.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 14
    Last Post: 08-27-2013, 01:16 PM
  2. Replies: 3
    Last Post: 12-29-2012, 01:21 AM
  3. Is an object array considered to be an object?
    By guest_user in forum New To Java
    Replies: 1
    Last Post: 07-13-2011, 07:40 AM
  4. Replies: 23
    Last Post: 09-07-2010, 09:12 PM
  5. Replies: 1
    Last Post: 04-17-2008, 11:10 PM

Posting Permissions

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