class rectangle

Thread Solved

Join Date: Nov 2004
Posts: 257
Reputation: sam1 is an unknown quantity at this point 
Solved Threads: 1
sam1's Avatar
sam1 sam1 is offline Offline
Posting Whiz in Training

class rectangle

 
0
  #1
Jun 21st, 2005
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 :-| :-|
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 257
Reputation: sam1 is an unknown quantity at this point 
Solved Threads: 1
sam1's Avatar
sam1 sam1 is offline Offline
Posting Whiz in Training

Re: class rectangle

 
0
  #2
Jun 21st, 2005
anyone??


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

any help i can get would be nice...
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 257
Reputation: sam1 is an unknown quantity at this point 
Solved Threads: 1
sam1's Avatar
sam1 sam1 is offline Offline
Posting Whiz in Training

Re: class rectangle

 
0
  #3
Jun 22nd, 2005
server_crash;

can you help please?
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: class rectangle

 
0
  #4
Jun 22nd, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 257
Reputation: sam1 is an unknown quantity at this point 
Solved Threads: 1
sam1's Avatar
sam1 sam1 is offline Offline
Posting Whiz in Training

Re: class rectangle

 
0
  #5
Jun 22nd, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: class rectangle

 
0
  #6
Jun 22nd, 2005
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:

  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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 257
Reputation: sam1 is an unknown quantity at this point 
Solved Threads: 1
sam1's Avatar
sam1 sam1 is offline Offline
Posting Whiz in Training

Re: class rectangle

 
0
  #7
Jun 22nd, 2005
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;
}
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: class rectangle

 
0
  #8
Jun 22nd, 2005
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:
  1. public void getLocation()
  2. {
  3. return new Point2D(this.x,this.y);
  4. }
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 257
Reputation: sam1 is an unknown quantity at this point 
Solved Threads: 1
sam1's Avatar
sam1 sam1 is offline Offline
Posting Whiz in Training

Re: class rectangle

 
0
  #9
Jun 23rd, 2005
thanx man this worked!!! :p :p :p
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 3
Reputation: S.T is an unknown quantity at this point 
Solved Threads: 1
S.T S.T is offline Offline
Newbie Poster

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

 
0
  #10
Jul 7th, 2005
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
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC