This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Micro Frontends in Action and have Michael Geers on-line!
See this thread for details.
Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!

Carey Brown

Bartender
+ Follow
since Nov 19, 2001
Carey likes ...
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
Forum Moderator
Carey Brown currently moderates these forums:
Colorado, USA
Cows and Likes
Cows
Total received
66
In last 30 days
1
Total given
4
Likes
Total received
1347
Received in last 30 days
15
Total given
194
Given in last 30 days
3
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Carey Brown

I would seriously consider refactoring your BTNode(String) method.
  • Break it into two methods with one doing nothing but matching closing parens.
  • Use a 'current' local variable instead of 'root'.

  • Here's an example of the helper method.
    You can use the return value as a parameter to a substring() call.
    5 minutes ago
    Your BTNode toString( BTNode ) method is  accurate, but hides misinterpretation of the parens during parsing. In this method, replace the parens with "<" and ">" and you get:
    NOW you can see the problem
    6 hours ago

    Even though you've written this as a recursive method it never get to call itself, therefore, the entire string is treated as one node.
    6 hours ago
    Nit pick: I tend to think of a "root node" as the root of the entire tree, not the root of a branch. Why not just call it "node"?
    8 hours ago
    Line 53: you need to leave off "root."
    9 hours ago

    Carey Brown wrote:I'm still thinking this through, but it seems that you shouldn't be using 'root' when you are inside a recursive method. That you should be passing the current node you are working on down through the recursion.


    Or rather, using a local variable 'current' as opposed to 'root' and then returning 'current'. This would mean  that the constructor would need to assign the returned value to root.

    Nit pick: It is a Java convention that all methods begin with a lower case letter. BTree() does not follow that convention and is confusing. It is also confusing to have both 'root' and 'this.root' in the same method, implying that there are two separate variables when, in fact, they are the same.
    9 hours ago
    For example
    Translates into
    19 hours ago
    I'm still thinking this through, but it seems that you shouldn't be using 'root' when you are inside a recursive method. That you should be passing the current node you are working on down through the recursion.
    19 hours ago
    I would take the time to write a method that would print out an indented diagram of the tree, or perhaps reconstructing a parenthesized string from a tree. Then inject that print into your code so that you can watch the progression of the tree being built. That would tell you a lot.
    19 hours ago

    Campbell Ritchie wrote:Actually it should be right and down rather than down and right.

    The (0, 0) point is at the top left of the screen. Carey is assuming screen pixels.


    Well, I was assuming screen pixels, but it is a coordinate system with the origin in the upper left corner increasing to the right and down. You can verify this by the assertions of the rectangle intersections.
    1 day ago
    I think your comparisons are backwards. Remember that X and Y increase as they go down and to the right.
    1 day ago
    Magic numbers are very bad. It is best to replace them with named constants that describes them. This makes the code more readable and the coding less error-prone.

    Anyway, I'm closing down for the night. Good luck.
    1 day ago
    Instead of magic numbers like '1', you could use PandemicModel.GREEN which would make the code more readable.
    1 day ago