Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Need help passing values through classes

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    11
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Need help passing values through classes

    This is a pretty basic concept, but I'm struggling with it. I've got three classes that I'm using for an assignment, basically, I'm passing over a string of a number into a class that parses the number and stores each individual piece of the number in different nodes as a linked list. My problem lies in sending over the number in the first place. I don't want to make my method static, so i have a bit of a problem.


  2. #2
    Member
    Join Date
    Jul 2010
    Location
    Washington, USA
    Posts
    307
    Thanks
    16
    Thanked 43 Times in 39 Posts

    Default Re: Need help passing values through classes

    In the class that parses the string you can pass the string through a constructor, or a method. I'll show you how to do it with a constructor.

    //this is the class that does the parsing
    public class parsingClass { 
       String stringToParse;
     
       public  parsingClass(String stringToParse){
          this.stringToParse = stringToParse; //Sets the string in this class to the one passed as an argument
       }
     
       //TODO: method that parses the string
    }
    and
    //this will be the main class, or the one that passes the string to be parsed.
    public class assignmentMain {
       public static void main(String[] args){
          parsingClass parsingClass = new parsingClass(String of numbers here);
          //Rest of code
       }
    }

    This should be a gentle nudge in the right way.
    Last edited by Brt93yoda; October 5th, 2010 at 10:05 PM.

  3. The Following User Says Thank You to Brt93yoda For This Useful Post:

    Jared (October 6th, 2010)

  4. #3
    Junior Member
    Join Date
    Oct 2010
    Posts
    11
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Re: Need help passing values through classes

    Thanks, I appreciate the response. I ultimately got past it last night, and it was a weird mistake to make. It's just been a while since I programmed, school just started back up.

Similar Threads

  1. New to vectors passing parameters
    By osmaavenro in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 30th, 2010, 04:32 PM
  2. [SOLVED] Class not passing information
    By DiPep in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 26th, 2010, 10:04 AM
  3. Passing in more than one flag
    By anon181 in forum Loops & Control Statements
    Replies: 3
    Last Post: February 2nd, 2010, 05:37 AM
  4. Passing Information between classes
    By SKhoujinian91 in forum Object Oriented Programming
    Replies: 4
    Last Post: December 8th, 2009, 02:40 PM
  5. How to share variable values amongst different classes?
    By igniteflow in forum Object Oriented Programming
    Replies: 8
    Last Post: August 20th, 2009, 08:53 AM