944,084 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 5104
  • Java RSS
You are currently viewing page 1 of this multi-page discussion thread
Jun 21st, 2005
0

class rectangle

Expand Post »
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 :-| :-|
Similar Threads
Reputation Points: 10
Solved Threads: 1
Posting Whiz
sam1 is offline Offline
300 posts
since Nov 2004
Jun 21st, 2005
0

Re: class rectangle

anyone??


please it is important!!!!!!!!!!!!!!!!!!!!

any help i can get would be nice...
Reputation Points: 10
Solved Threads: 1
Posting Whiz
sam1 is offline Offline
300 posts
since Nov 2004
Jun 22nd, 2005
0

Re: class rectangle

server_crash;

can you help please?
Reputation Points: 10
Solved Threads: 1
Posting Whiz
sam1 is offline Offline
300 posts
since Nov 2004
Jun 22nd, 2005
0

Re: class rectangle

What exactly are you having problems with during the use of get and setLocation()... You can specify an x and y int as arguments or pass a point to it. You'll have to be more specific before I can really help.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Jun 22nd, 2005
0

Re: class rectangle

for the set method ive got x and y for parameters. the problem ive got is with get method. how can i return x and y in the same get method?
thnx
Reputation Points: 10
Solved Threads: 1
Posting Whiz
sam1 is offline Offline
300 posts
since Nov 2004
Jun 22nd, 2005
0

Re: class rectangle

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:

Java Syntax (Toggle Plain Text)
  1.  
  2. public Point2D getLocation()
  3. {
  4. return Point2D();
  5. }
  6.  
  7. public int getX()
  8. {
  9. Point2D p = getLocation();
  10. return p.getX();
  11. }
  12. public int getY()
  13. {
  14. Point2D p = getLocation();
  15. return p.getY();
  16. }

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.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Jun 22nd, 2005
0

Re: class rectangle

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;
}
Reputation Points: 10
Solved Threads: 1
Posting Whiz
sam1 is offline Offline
300 posts
since Nov 2004
Jun 22nd, 2005
0

Re: class rectangle

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)
  1. public void getLocation()
  2. {
  3. return new Point2D(this.x,this.y);
  4. }
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Jun 23rd, 2005
0

Re: class rectangle

thanx man this worked!!! :p :p :p
Reputation Points: 10
Solved Threads: 1
Posting Whiz
sam1 is offline Offline
300 posts
since Nov 2004
Jul 7th, 2005
0

RE: hi i'm tring to do this point 2d and oblong class

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
S.T
Reputation Points: 10
Solved Threads: 1
Newbie Poster
S.T is offline Offline
3 posts
since Jul 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: securing code on a webserver
Next Thread in Java Forum Timeline: Need help moving an object across screen





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC