| | |
class rectangle
Thread Solved |
hi every one
i am doing this coursework where i have to design two class one is:
Point2D, that models a two-dimensional point.
The second class implement a class Oblong(rectangle) from a given specification and will require the use of the Point2D class. 1. A Oblong specifies an area in two-dimensional (2D) space which is enclosed by the Oblong object's location, (i.e. its top-left corner ( x, y ) in the 2D-space), its width and its height.
i have no problem with point2d, but in oblong(rectangle) there is two methods(setlocation and getLocation) where set location modifies the co-ordinates of a rectangle’s top-left corner and getlocation the position of the rectangle’s top-left corner.
i can seem to come around those two methods, i tried everything but could not solve it.
i appreciate any one giving me help.
thanks :-| :-|
i am doing this coursework where i have to design two class one is:
Point2D, that models a two-dimensional point.
The second class implement a class Oblong(rectangle) from a given specification and will require the use of the Point2D class. 1. A Oblong specifies an area in two-dimensional (2D) space which is enclosed by the Oblong object's location, (i.e. its top-left corner ( x, y ) in the 2D-space), its width and its height.
i have no problem with point2d, but in oblong(rectangle) there is two methods(setlocation and getLocation) where set location modifies the co-ordinates of a rectangle’s top-left corner and getlocation the position of the rectangle’s top-left corner.
i can seem to come around those two methods, i tried everything but could not solve it.
i appreciate any one giving me help.
thanks :-| :-|
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
Im pretty sure that the get method returns a point....From there it's up to the recipitent of the point to call the getX() getY() methods on that point. There's really now way to return both of those. You can create your own methods that could do something like this:
You'll have to check to make sure I'm right about getX() and getY()...I'm pretty sure that those exist, but make sure.
Java Syntax (Toggle Plain Text)
public Point2D getLocation() { return Point2D(); } public int getX() { Point2D p = getLocation(); return p.getX(); } public int getY() { Point2D p = getLocation(); return p.getY(); }
You'll have to check to make sure I'm right about getX() and getY()...I'm pretty sure that those exist, but make sure.
hi server_crash
i did it the way you told me but did not work.... i am puzzled as well
the task says:
provide an accessor getlocation() that retrieves the position of the rectangle's top left corner.
for the mutator setlocation() i have done this:
//mutator method
public void setLocation(int xLeft, int yLeft)
{
super.x = xLeft;
super.y= yLeft;
}
i did it the way you told me but did not work.... i am puzzled as well
the task says:
provide an accessor getlocation() that retrieves the position of the rectangle's top left corner.
for the mutator setlocation() i have done this:
//mutator method
public void setLocation(int xLeft, int yLeft)
{
super.x = xLeft;
super.y= yLeft;
}
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
GetLocation() probably needs to make a call to the Point2D class. I'm guessing your class has a constructor that takes two arguments, an x and a y. If so, you could say:
Java Syntax (Toggle Plain Text)
public void getLocation() { return new Point2D(this.x,this.y); }
•
•
Join Date: Jul 2005
Posts: 3
Reputation:
Solved Threads: 1
Hi,
I am trying to do this point 2d and oblong class aswell, but i am having some trouble with the oblong class which has some of the fucntions like:
Provide a Boolean method isEmpty
Provide a Boolean method intersects
Provide a method shrink( int a, int b ) which takes a rectangle and returns a rectangle with the same top-left vertex but whose width and height are reduced by amounts a, b respectively
Provide an appropriate operation, union, that returns the smallest rectangle that contains both this rectangle and the specified rectangle
Provide an appropriate operation, intersection that returns the largest rectangle contained in both the specified rectangle and this rectangle; the method should return an empty rectangle if the two rectangles do not intersect
Provide any additional member methods that are appropriate for your class, including overloaded versions of existing methods, where meaningful.
if any body can help me i would be much appreciated as i am completly stuck with this part
Thank
S.T
I am trying to do this point 2d and oblong class aswell, but i am having some trouble with the oblong class which has some of the fucntions like:
Provide a Boolean method isEmpty
Provide a Boolean method intersects
Provide a method shrink( int a, int b ) which takes a rectangle and returns a rectangle with the same top-left vertex but whose width and height are reduced by amounts a, b respectively
Provide an appropriate operation, union, that returns the smallest rectangle that contains both this rectangle and the specified rectangle
Provide an appropriate operation, intersection that returns the largest rectangle contained in both the specified rectangle and this rectangle; the method should return an empty rectangle if the two rectangles do not intersect
Provide any additional member methods that are appropriate for your class, including overloaded versions of existing methods, where meaningful.
if any body can help me i would be much appreciated as i am completly stuck with this part
Thank
S.T
![]() |
Similar Threads
- a simple overloaded class consturcotor problem (C++)
- Help regarding rectangle moving (Java)
- cant construct rectangle (Java)
- Help : Pointers to array of class objects . (C++)
- confused with errors in c++ (C++)
Other Threads in the Java Forum
- Previous Thread: securing code on a webserver
- Next Thread: Need help moving an object across screen
| Thread Tools | Search this Thread |
911 addball addressbook android api append applet application apps array arrays automation binary bluetooth businessintelligence button card chat class client code collision component crashcourse css csv database eclipse ee error fractal free game gis givemetehcodez graphics gui html ide image integer integration j2me japplet java javaarraylist javadoc javafx javaprojects jni jpanel julia jvm linux list loan machine map method methods migrate mobile netbeans newbie objects oriented output panel phone physics problem program programming project projects radio recursion replaydirector reporting scanner se server service set sms socket software sort sql string swing test textfield threads transfer tree trolltech ubuntu utility windows






