Fred Hamilton

Ranch Hand
+ Follow
since May 13, 2009
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 Fred Hamilton

Thanks.

No main method.  doh!  Excuse me while I kick myself
6 years ago
Greetings

This should be easy. Here is my code



and here is the compiler errors I get

com/fwh/test/Test1.java:9: error: <identifier> expected
System.out.println(className);
                                ^
com/fwh/test/Test1.java:9: error: <identifier> expected
System.out.println(className);
                                                       ^
As you can see, the compiler doesn't like my println statement, but it looks fine to me. What am I doing wrong
6 years ago
I have found that this site is an excellent choice for beginners.

http://chortle.ccsu.edu/java5/index.html
8 years ago
Heavy Sigh I should make a rule for myself. Whenever I am about to post to a message board concerning a debugging problem, make sure I check for the extra semicolon first; I am aware of what can happen when this mistake occurs, not sure why I missed it.

Thanks for the quick reply.
8 years ago
Greetings. I am trying to write a program that reads from standard input and echoes to the monitor only those lines that begin with "//". It is a prototype for a program which will print out the comments from a java source file. The problem is that the program is echoing everything I type and not just those lines beginning with "//". Here is my code. I must be missing something obvious, but I just can't see it.

8 years ago
Thanks for the quick replies. It all makes sense now. And if I had read a few more pages I would have found the answer.
8 years ago
Greetings

I am trying to resolve a conflict in information that is appearing in a java tutorial I am reading.

on the first page http://chortle.ccsu.edu/Java5/Notes/chap25/ch25_17.html it says that a new string object won't be created if the identical object already exists. Here this is described as an optimization.

on the second page http://chortle.ccsu.edu/Java5/Notes/chap26/ch26_20.html is an example that seems to directly contradict the first statement. In this example a second object is created when an identical object already exists. I verified this by running the example, and the == operator comparing the two references returned false.

So what am I missing?
8 years ago

Henry Wong wrote:
When it comes to recursion, I am definitely *not* a fan of learning by example.

If you look at a solution, in my opinion, at best, you just learn how that solution works. And if you are unlucky, you only think you know how it works.

Recursion requires a way of thinking out the problem. And if you never try to figure it out, with the easy examples, how can you do the hard ones? You need to mentally exercise your recursion muscles, on the easy problems, to be strong enough for the hard ones.

Henry



I disagree, but you're the mod, so my opinion must be wrong. sigh. I knew there was a reason why I quit this board. Too many people who insist that their way is the best.
13 years ago
You might benefit from having a look at the recursive solution to the factorial problem. The factorial problem does have one or two things in common with your array problem.

Here is where I got my feet wet with recursion:

http://erwnerve.tripod.com/prog/recursion/recintro.htm
13 years ago
Eckel is ok, he has an interesting and somewhat different approach to java which I found helpful when I needed additional insights into interfaces, abstract classes, polymorphism, etc.

But, and it's a pretty big but, in my opinion he plays fast and loose with terminology, which could easily be confusing to a beginner, or someone who struggles with semantics

Perhaps one of the mods would care to comment on this aspect of Eckel.

regards.
13 years ago
The following page helped me a lot. It does not discuss the most current layout managers, such as box layout, but it does a great job of explaining the concepts.

http://java.sun.com/developer/onlineTraining/GUI/AWTLayoutMgr/shortcourse.html
13 years ago

Rene Rad wrote:

Fred Hamilton wrote:

Rene Rad wrote:I think I get it.

Does x.length ALWAYS start at 1? If so I guess I should never use '(or)equals to' but rather always less than.

Is this correct?



the issue is that array indexes start at 0. if the array has length 10, then we have elements numbered 0,1,2,3,4,5,6,7,8,9.

Count em. There's 10 numbers there.



I understand that, 0 is still a number. does .length always start at 1?



You certainly don't give the impression of understanding it. Whether or not length starts as 1 doesn't tel you whether or not to use < or <=. Anyways, good luck with it. Try to think a bit longer before you reply

13 years ago

Rene Rad wrote:I think I get it.

Does x.length ALWAYS start at 1? If so I guess I should never use '(or)equals to' but rather always less than.

Is this correct?



the issue is that array indexes start at 0. if the array has length 10, then we have elements numbered 0,1,2,3,4,5,6,7,8,9.

Count em. There's 10 numbers there. An array with length = 1 has only one index, 0
13 years ago

Matt Cartwright wrote:just wondering ..

java.awt.geom.Point2D distanceSq(Point2D point)

Distance Formula

M



Yeah, except that method tells us the distance given two points, We know the distance, we don't know the 2nd point. So I don't see how we can use your method, but if you do, then I'm all ears. regards.
13 years ago

Alec Lee wrote:Thanks. I am working hard to recall my math knowledge. I show what I've done and see if it is correct or not:

Assuming the point is (xp,yp), then

From 2 point form I get the equation of the line as: (yp-y1)^2 * (x1-x2)^2 = (xp-x1)^2 * (y1-y2)^2 ......(1)
(I took square of the equation for easy substitiion with my 2nd equation)

From distance between 2 point formula: d^2 = (yp-y1)^2 + (xp - x1)^2 .......(2)

And, now it is 2 equations with 2 unknown. It could be solved by eliminiation. Since, I got (yp-y1)^2 in both equations, I can take the one in (2) and substitute it into (1) to get xp. And with xp known I just find yp from (1).

Is that correct?



I am not so sure about equation 1, it doesn't seem right, or else it is too complicated. equation (2) is correct.

may I suggest a slightly different way of doing.

ok, you have two unknowns x & y, and 4 "knowns" x1, y1, x2, y2
Since you have two unknowns you need two equations.

now the slope of the line is given by slope = (y2-y1)/(x2-x1). This is a known number, not a variable,.

since the point (x,y) is on the same line, it must fit into that formula, so the first equation is

A: (y-y1)/(x-x1) = slope.

now we get the second equation from pythagorus theorem

B: d^2 = (y-y1)^2 + (x-x1)^2

since you know what d is you now have two equations in two unknowns (x & y), and you should be able to sole this by substitution.

hopefuly that is a little clearer. my math is a little rusy too, but I'm pretty sure this is right.
13 years ago