John Wickerson

Greenhorn
+ Follow
since Mar 16, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
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 John Wickerson

great, thanks for your suggestions guys.

Could I pick your brains further?

What if I now wanted to check if there were any words *beginning* in a certain string. For example, "AP" should give true (since APPLE is a word), while "XJ" should return false.

I've thought about storing the words in some sort of tree, with up to 26 branches per node, one per letter. But this seems a rather complicated approach, and I'm not sure I'm up for it!

Is there a method in HashSet perhaps, like contains(), that would be able to efficiently find words starting with a certain string?

Thanks ever so much,

John
16 years ago
Hi guys,

I have a large text file containing 216556 words, one per line, in alphabetical order.

I want to make a procedure that, given a word (in String or char[] form, I don't mind), returns true if that word is in the list, false otherwise.

Firstly, would it be feasible to store this in memory, perhaps as some sort of array, or maybe as some sort of tree? Or will I have to keep it on disk? And if I keep it as it is, on disk as a text file, is there a way to jump straight in to the 123rd line, or do I have to search from the beginning of the text file for each word I want to check?

Thanks guys - much appreciated!

John
16 years ago
Hey guys,

When I start my applet with appletviewer, I get a white window saying "Hello".
When I make my applet window bigger, I get a blue/grey window that is blank.
When I make my applet window smaller, I get a blue/grey window that says "Hello".

What is the reason for this strange behaviour? I simply want "Hello" to be always positioned in the middle of the screen.

Here is my code:


Thanks for any suggestions you may have...

John
16 years ago
(Update)
I've now fully implemented the new version as suggested. It works beautifully, so thanks for suggesting it!

John
16 years ago
Hmm, I did suspect that what I was doing wasn't particularly 'good coding' . I'll have a go at using your suggestion. Off the top of my head I'm thinking the new Operand class would be something like this:A nicety of doing it this way is that o1 could be set and o2 left Null for an operation like negation that takes only one operand.
16 years ago
Thanks Jeff and Tony. I must admit it's quite a satisfying feeling when I finds that my question does not have a blindingly obvious answer that I should have seen. Since I'm only using the ArrayReader with chars at the moment, I guess I'll fix it to become a CharArrayReader instead.

Regards,
John
16 years ago
(UPDATE)

I thought I'd let you know that I've come up with what I think is a reasonably good solution to the problem - I'd still appreciate your comments on my solution or any better solutions...

I now use



And the abstract class Operand has the static method makeEx:



Cheers,
John
16 years ago
Hey guys,

I have a fairly general question on Java.

I'm having a bash at writing a program that parses an expression. That is, it is given input such as the string "(x+5)*(x-4)", then it works out the 'expression tree' that represents the expression, which in this case would be:



Now, I have the superclass Operand, which has two children classes: Branch and Leaf. Each node on the above tree is either a Branch or a Leaf. The operations (e.g. x-4) are Branches, and always consist of two Operands and one Operator. The constants and variables are Leaves, and simply consist of a value.

Now to my question.

How to create the expression? I am currently using

This works great 99% of the time. However, if my expression is simply a constant, such as 5, ...

... it doesn't work, because clearly, 5 is a Leaf not a Branch. I have to use:

but this clearly isn't as good, because I have to decide whether the string represents a Leaf or a Branch before even constructing the expression. Ideally, I would make the expression with code like the following:

This would be nice because the class Operand encompasses Branches and Leaves. Unfortunately, Operand is an abstract class, and I feel it is best to keep it that way.

Any advice would be gratefully received...


Kind regards,
John
16 years ago
Hey guys,

I have the following code, which I'm using to read each element from an array in turn. I've recently modified it to work with an array of any type, but it no longer works.



When I use it like this, I am told that the constructor ArrayReader<Character>(char[]) is undefined.



What's going on here? Thanks v much for any help....

Kind regards,
John
[ March 28, 2006: Message edited by: John Wickerson ]
16 years ago
Hi Ulf, thanks for your reply. I gather that it's a fairly tricky topic getting applets to import your own custom classes.

So for the moment I would suggest that you create a single directory containing all your classes, and copy files over to the public directory as needed.



Is this what you would do? If there is a more advanced but better way of doing it, I would very much like to know (even if it is too advanced for me to understand - it will provide me with a starting point). Thanks.


Kind regards,
John
16 years ago
Hey guys,

Well first of all, please let me say how nice this website is - I'm very pleased to have found it and plan to be sticking around while I'm learning Java as part of my Uni course.

I think I will probably get off to pretty bad start here, by asking a question that is almost certainly a 'Frequently Asked Question'. In my defence, I have looked at quite a few sites on the net and not found the answer.

First, I'll set the scenario...

I'm running java on Linux. My $CLASSPATH variable is set correctly to "/home/jpw48/public_html/java/classes". I have made myself a package which we'll call myPackage. This contains the class Jack.class , so the full location of Jack.class is "/home/jpw48/public_html/java/classes/myPackage/Jack.class". Now, I have 'local' directory, which contains the file Jill.class at "/home/jpw48/java/jill/Jill.class". Jill imports Jack using the statement "import myPackage.Jack;".

Still with me?

Now, Jill extends JApplet, so to run Jill, I have to make Jill.html, which includes the line:

<APPLET code="Jill.class" width="1000" height="800">

I use the command "appletviewer Jill.html" to run Jill, but it doesn't work, complaining of a NoClassDefFoundError at runtime. Clearly, it doesn't know where to find Jack. After some trawling through the internet, I found a way to solve this problem by giving the command:

appletviewer -J-classpath -J$CLASSPATH Jill.html

And this works fine. So what's the problem? The problem is if I try to open Jill.html with my normal browser like this...

firefox Jill.html &

... it doesn't work for the same reason as why appletviewer didn't work initially - it doesn't know the classpath. There's no command line parameter I can give to firefox to tell it the classpath; it's got to be put into the html file somehow, I reckon.

How?

Thanks guys, I look forward to hearing your response(s).

Kind regards,
John
16 years ago