Repeal Obamacare.
http://www.dontfundobamacare.com/
http://liberty-amendments.freeforums.net/
Paul Clapham wrote:Well, I haven't looked at all of your code (there's rather a lot) but the first thing I would do would be to get rid of lines 5 and 6 in the posted code. You don't need to store anything but the location of one corner and the width and the height.
And frankly I would make a Rectangle object immutable, i.e. I wouldn't have any setter methods at all. I would just have a constructor which accepted x, y, width, and height and a set of suitable getters, but no setters. This would make questions like "why is the height changing?" go away.
Repeal Obamacare.
http://www.dontfundobamacare.com/
http://liberty-amendments.freeforums.net/
[My Blog]
All roads lead to JavaRanch
Christophe Verré wrote:I haven't been looking at your problem, just at the code, and I see at least one issue. You forgot to set upperX and upperY in "public Rectangle(Rectangle a)". To avoid that, you should make one initialize method and call it from both constructors.
Repeal Obamacare.
http://www.dontfundobamacare.com/
http://liberty-amendments.freeforums.net/
Paul Adcock wrote:However, now I think I understand what it means by "immutable". It means that, outside the class, you can't reset variables. You might be able to reassign a class object but not a variable of the class.
Paul Adcock wrote:I was trying to make a Rectangle class...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Paul Adcock wrote:I was trying to make a Rectangle class...
Paul,
Could you please re-read the UseCodeTags page again? And when you've done that, perhaps you could break up some of those enormous lines inside the tags; they screw up the windowing here. I'd do it for you, but they're all over the place. Just use the 'Edit' key to change your posts.
Personally, I can hardly read this thread, and I suspect you're missing out on lots of answers as a result.
Winston
Repeal Obamacare.
http://www.dontfundobamacare.com/
http://liberty-amendments.freeforums.net/
Repeal Obamacare.
http://www.dontfundobamacare.com/
http://liberty-amendments.freeforums.net/
Campbell Ritchie wrote:No, long lines are harder to read than broken lines. Read this about line length. Apart from the missing {} that code formatting doesn’t look bad now.
Repeal Obamacare.
http://www.dontfundobamacare.com/
http://liberty-amendments.freeforums.net/
Consider Paul's rocket mass heater. |