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.
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.
Code java:
//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
Code java:
//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.
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.