Campbell Ritchie wrote:Don't try doing arithmetic on pairs found in arrays like that; it is very error‑prone. Create an XYPair class and put the two coordinates in that. Are you aware of the two Math class methods used for polar coordinates: 1 2?
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger wrote:A constructor can take any object type - it's a parameter like anything else.
So, if you have a Cartesian object, you can pass it in to the Polar constructor to make a Polar object. And vice versa. The input to Polar is an object of type Cartesian.
You sometimes also pass a second Cartesian object into a Cartesian object...for example, if you want the distance between two. Assume I have two points:
The Cartesian class may have a distance method, that takes a Cartesian object - after all, you need two points to compute a distance:
--update---
i looked at your source a little closer...you have this method:
So...assuming you have two Polar objects polar1 and poloar2, you would get the distance by doing this:
No, it is usually a bad idea to let nulls run free. You are telling the JVM, “Here isn't an object, call the getY method on it,” and the JVM tells you in no uncertain terms that it can't do anything on non‑existent objects.paul spriesterbach wrote: . . . It looks like to me it isnt liking the null I am inputting in to the Cartesian objects. . . .
Campbell Ritchie wrote:
No, it is usually a bad idea to let nulls run free. You are telling the JVM, “Here isn't an object, call the getY method on it,” and the JVM tells you in no uncertain terms that it can't do anything on non‑existent objects.paul spriesterbach wrote: . . . It looks like to me it isnt liking the null I am inputting in to the Cartesian objects. . . .
Try new Polar(new Cartesian(123.45, 678.90))
You may have to give your classes constructors which take x and y or ρ and Θ as parameters directly.
Why haven't you used both methods I told you about earlier? The one you haven't used would help in the distance between two points problem, I think.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |