Fun Stuff > CLIKC

A programming thread!

<< < (12/37) > >>

danpaul88:
Yeah, I'm mostly just using SE features but from what I've read it looks like the EE stuff can be leveraged to make a cleaner interface for accessing the Java code from a web server without some sort of intermediary between the two.

Pilchard123:
Netbeans is a good IDE as well, though that opinion might be coloured by it being the first one I used seriously.

ankhtahr:
So I think I've managed this line segment intersection stuff. There's room for errors due to rounding errors, but I'm relatively sure I don't have to compensate for that.

I now have a different problem, more programming related. Anybody have a nicer way for doing what I have to do here?

l still have the same structure, so a point is an object with two double values for coordinates, a line is defined by two points, a triangle by three. I now have to write a constructor to create a triangle from three lines.

I'd now put all the points I have into an array, and for every element I'd have to check, whether it's equal to another element. If I don't get three matched pairs I can't make a triangle from it. But this doesn't really feel elegant to me…

snalin:
It's not elegant, and it doesn't work - it allows stuff like three parallel lines. You'll need to test both that there are three matched pairs, and no element that matches more than one other element.

I'd just put the endpoints of the three lines in a list of some sort (or array if you wanna be old fashioned about it), and test that every element has two objects in the list that's equal to themselves - the other point and itself. Also, use object equality on the Points, don't manually check their x- and y-axis values in your triangle constructor.

Also, you probably know this, but a reminder to everybody that's starting up with Java - '.equals' is not the same as '==' , unless you forgot to write the equals method in which case it still only check for reference equality. So this code prints false:

--- Code: ---ArrayList<Integer> list = new ArrayList<>();
ArrayList<Integer> list2 = new ArrayList<>();
list.add(5);
list2.add(5);
System.out.println(list == list2);

--- End code ---

This is where you really, really, really want to start using unit tests in a proactive way - test driven development is the nice way. If you don't know JUnit, familiarize yourself with it. Write tests for triangles that should work, and triangles that shouldn't. Start with obvious examples, and continue with harder ones. It's not really necessary, but if you are familiar with the technique, everything in your life will be a lot easier. Trust me.

ankhtahr:
JUnit tests and stuff like that are exactly what we're taught in the software engineering class.

Sadly we're not allowed to use lists, but I'll see what I can do with arrays.

And thanks for pointing out the parallel lines. I really didn't think of that.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version