Results 1 to 5 of 5

Thread: how to change a string in an array to int ??

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2002
    Location
    Kentl
    Posts
    7

    how to change a string in an array to int ??

    Hi everyone, I am only learning java so please
    excuse me if seems a silly question.
    I have done a 2d array

    start car destination time
    Code:
    {{london,   ford,         leeds,                 90}
     {london,   vauxhall,   ipswitch,             85}
     {leeds,     ford,          manchester,      80}}
    I know in an array all val's are of type string
    what i need to do is a method to change time to int

    ie. if i call london to leeds using ford it will
    display time at 90, i would then want to call leeds
    to manchester which should add 90 + 80 giving a time
    of 170.
    any idea's as I have been trying to find out how to make a object
    in an arry and declare that object as a int(time)

    would be grafull if any one can point me in the right direction

    thanks
    Lindsey

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I have no idea what you want to do, but you're misusing arrays in the PHP way.

    What you should have is a 1d array of objects of a class that looks like
    Code:
    public class Route
    {
      private String from;
      private String to;
      private String car;
      private int time;
    
      // and some public methods to make the class useful
    }
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2002
    Location
    Kentl
    Posts
    7
    Thanks CornedBee,

    It makes sense what you say, i will have a go at that myself
    but my lessons in school have not covered the way you said as they went on about 2d and 3d arrays and then told us to do this home work. I know you will be right so I will try your way even if it upsets the teacher as i want to learn how you supposed to things the best way

    thanks lindsey

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    You're learning Java and doing 2d arrays prior to classes

    Another terrible programming class...
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2002
    Location
    Kentl
    Posts
    7
    yes you are right, but i am learning a lot more about java from books and reading the post on this forum than from class which is why i feel silly coming on to ask questions all the time.
    well i wish you all out their a good night

    thank again for advise
    lindsey

Posting Permissions

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



Click Here to Expand Forum to Full Width