This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have a polygon, and I'm running through its PathIterator and printing out every point. For some reason, it's printing the last point twice. I would've understood if it printed the FIRST point again at the end (I would've assumed it had "circled back" to the first point), but I don't understand why it's printing the LAST one twice. Here is my code:
(Note: please do not criticize the improper OO design... I am just testing out how Shapes work, I have a homework assignment which I will do with proper OO once I've gotten the hang of these shapes)
[ February 16, 2008: Message edited by: Gloria Connors ] [ February 16, 2008: Message edited by: Gloria Connors ]
I was cringing at the poor OO design of Polygon and PathIterator, that make this so hard to use. Your own program looks fine. To understand what's going on here, you need to look at the return value of the currentSegment() method. Look at the API to understand what the possible return values mean. You may find it useful to write a short method to convert an int return value into a short string which describes what that value means. (In modern Java they would have used an enum type here, but those didn't exist back when this was written.) Use this method to print the type of each path segment, and see what's going on. [ February 16, 2008: Message edited by: Jim Yingst ]