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 :-| :-|

Recommended Answers

All 13 Replies

anyone??


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

any help i can get would be nice...

server_crash;

can you help please?

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.

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

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:

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;
}

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:

public void getLocation()
{
     return  new Point2D(this.x,this.y);
}

thanx man this worked!!! :p :p :p

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

can any body help!!!!!!!

Where's your work and why are you posting in someone elses thread?

Hi everyone,

can any body help!!!!!!!

Dude i don't mean to ride you up but server_crash is right why are you hijacking someone else's thread. If you want help post a thread so people can help you

Richard West
*****************************************************

hi server crash it's S.T

As you asked where is my work, i have attached it below and if you could help me to get this program looking right.


package oblong;

oblong()
{
x =0;
y =0;
width = 0;
height = 0;

}

public point2d getLocation()
{
int topleftx = x;
int toplefty = y;
point2d (topleftx, toplefty);
return point2d;
}

public int getX()
{
point2d p = getLocation();
return p.getX();
}
public int getY()
{
point2d p = getLocation();
return p.getY();
}


public void getLocation()
{
return new point2d(this.x,this.y);
}


public Boolean empty ()
{
return()
}

public int getwidth()
{
return width;
}

public int getheight()
{
return height;
}


public oblong operator (oblong)
{
bool operator ==(const oblong&) const;
bool operator!= (const oblong&)const;

}

public int findArea()
{
return (length * width);

}

void setsize (int, int)oblong
{
oblong r1 = new oblong ();
oblong r2 = new oblong(4,3);

}

void translate (int, int)
{
for (int i =0; <rpoints; i++)
{
x points + = x;
y points + = y;
}
}


i am having trouble with the void translate, oblong shrink( int, int), bool contains (int, int), bool intersects(oblong r).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.