Noam Ingalls

Ranch Hand
+ Follow
since Jan 11, 2012
Noam likes ...
Firefox Browser Chrome Linux
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Noam Ingalls

Right, got it... problem fixed. Thanks.
12 years ago
I've got an int that I need to pass into another class's method; what's the best way for me to do that? Declare the int as static? Although it wouldn't help right? Make it a separate method? Or try and use setters and getters which I don't really understand?

The int is keeping track of how many lines have been processed; I set up a loop to read the lines in the array myString, and used a variable called lineCounter to keep track in the method parseCommands in the main. Now I need the value of lineCounter to be passed into this class EndStatement; not sure how to get it in there though. Can someone help, or link to an example that shows how? Thanks!



Class I need to get the variable into:




12 years ago
So for the above kind of example I'd need multiple splits? Hm... What other ways apart from regex and String.split() would there be to split a string, apart from String Tokenizer though?
12 years ago

Jeff Verdegan wrote:

Also, let's say you had a String that did contain double quotes:


What would you expect the output to be in that case?



Ack, you're right, there's a problem right there. How should I get it to ignore double quotes inside other double quotes though? I've tried escaping the quotes, but of course like you'd expect the string got split on those quotes anyway.
12 years ago
I'm working on how to split strings with String.split(); I am using double quotes as delimiters for the strings; just want to remove the double quotes and print out the stuff in between them. It's going strange though; why is String.split eating the second part of my string? I'm not sure where I'm making a mistake with the regex.



Expected output:




Output currently displayed: the "world" is missing--?!

>
12 years ago
Thanks Joanne! That makes a whole LOT more sense than the mess I'm staring at in front of me right now. >.< Speaking of declaration statements it'd have to be the entire String e.g. STRING myString, right? In which case only one array would be needed. But again the first parsing splits the String into parts[0] and parts[1]-- maybe if later on in the classes I'd have to split the substring in parts[1] further by whitespace?
12 years ago
Ayup, Strings are Strings. I'll see if I can explain the program structure better: First off the data to be parsed is read into an ArrayList of Strings; next the Strings are parsed as keywords+(variables+ values). So the first parsing takes the keyword in the String, and directs it to the correct class e.g. StringStatement class via a HashMap. Now inside the StringStatement class I need to instantiate a new String from the information left from the first pass: that would be the variable (plus value). Now to aid in manipulating the data a second HashMap, variablesHash, is used to store the variable-value pairs. Variables have to be declared first before values are assigned; you can't assign a vlue to a variable on the same line directly. So inside the TPLVariables class is a second HashMap <String, TPLVariable>. This class also contains the abstract class TPLVariable, with two subclasses TPLInteger and TPLString, a getVariable() and an addVariable() function with the parameters (String name, value). My current question now is-- does it make more sense to instantiate every variable inside the TPLVariables class, and just have the *Statement classes provide a call to the addVariable function as necessary? I'd need to get the values for the String name and String value into the addVariable function somehow though. Thoughts?
12 years ago
All right. Well my dad raised no quitters. In for a penny in for a pound and all that-- I doubt my lecturer would be amused at a submission with partial functionality waaay over the deadline. My major issue now is with the parser classes-- StringStatement, IntegerStatement and LetStatement and CalculateStatement. I can handle Strings that have been declared in double quotes no problem, but it's handling variables that's the trouble. Now the Statement classes are supposed to handle all the data parsing. The data such as variable names and variable values go into a fnction called addVariable() in a separate HashMap called variableHash for easy manipulation. Now if I was going to need to create a new String or Integer variable, would it make more sense to you have all the parsing and instantiating in one place, and then in the *Statement classes, just have the one line to call the function addVariable() in the class?
12 years ago
Well, I already knew it was too big and I can now say I honestly detest this project; but it's 60% of my coursework grade for this module, which module I can't fail if I intend to progress in my degree, I'm a whole WEEK overdue and the marks on this thing have just about been deducted to zero, I guess. My final paper for this same module (programming) is tomorrow and I'm trying to finish this thing while cracking my head on the books. Right now I just want to get this program over and done with... At this point I don't know whether to throw in the towel and send in this already horrendously late submission with only partial functionality, or try and fix the problem...
12 years ago

Mohamed Sanaulla wrote:

Noam Ingalls wrote:Should I ask to close the other thread then or close this one? I think closing this one would be better since the original issue is kinda resolved.



Is this the other thread?



No, but come down to it the problem I was having when I asked that is fairly similar to my current issue here-- in fact, ugh, apologies, I think I've been posting too many new threads perhaps-- the problems are related, being all one project.
12 years ago
Should I ask to close the other thread then or close this one? I think closing this one would be better since the original issue is kinda resolved.
12 years ago
Huh. The thing is, the information that the TPLVariable class and its subclasses needs to work actually comes from the *Statement classes, which is why I was trying to get that particular value passed into the TPLVariable class. Not possible?
12 years ago
Hi. I keep getting hit with all these "cannot find symbol" issues: Basically I know where the variable "name" is; it's defined in the StringStatement and IntegerStatement classes (in the Directive interface). I'm trying to pass the "name" variable, which appears in different classes, to this method in the class TPLVariables which is supposed to populate the HashMap variables:




However if I try to use that method to print the value of the variable inside any of the *Statement classes e.g. StringStatement, I get
"error: cannot find symbol: System.out.println(TPLVariable.getVariable(name))"... Is this a scope issue? Also I'm not sure why but the program seems to think that variablesHash is a variable when it's a HashMap-- and it can't find that either. I'm getting 18 errors on compile (down from a whopping 28, huzzah!) and it's all from these two things. What's wrong and how do I get it fixed?






12 years ago
Uhm yeah, thanks for posting the fix, though I came to that conclusion myself already. Note to self-- make sure all names are very different in future. I'm getting another error message now though: This line is in a different class implementing an interface called Directive (different HashMap), but needs to get the variable "name" from TPLVariable... I'm getting a "cannot find symbol" error for "name", and it's also throwing this "non-static variable variables cannot be referenced from a static context".

The class in question:

>
12 years ago
TPLVariables is the class that has my HashMap in it, and TPLVariable is the abstract superclass for TPLString and TPLInt, so it's definitely not a subclass of TPLVariables.
12 years ago