Hey guys,
For one of my assignments, i got this little exercise:
"Add at the class Rectangle a method move(Point p) which
moves the rectangle in the point indicated by the parameter, a method
translate(int x, int y) which translates the rectangle to the right
along the 0x coordinate axis and downward along the 0y coordinate
axis, and a method setSize(int width, int height) which sets
the size of this rectangle to the specified width and height. Compile the
class Rectangle.
Define a class RectangleTest3 with the method main() which
creates a rectangle, moves, sets size and translates it. After each
operation the algorithm prints the coordinates of its left-top vertex, its
edges and area. Compile and execute RectangleTest3."
The problem I'm having is that i don't know if i interpreted the assignment correctly.
So far i have written this:
[B]Rectangle.java:[/B]
import java.lang.Math;
public class Rectangle
{
int x;
int y;
int height;
int width;
int ax;
int ay;
public Rectangle(int a, int b, int c, int d)
{
height=c;
width=d;
ax=a;
ay=b;
}
public Point move(int ax, int ay)
{
x = ax;
y = ay;
Point v = new Point(x, y);
return v;
}
}
[B]RectangleTest3.java[/B]
public class RectangleTest3
{
public static void main (String[] args)
{
Rectangle rec = new Rectangle(1, 3, 6, 7);
System.out.println("Coordinates of left-top vertex: ("+rec.x+", "+rec.y+")");
Point vertex = rec.move(rec.ax, rec.ay);
System.out.println("Rectangle Area: ("+vertex.x+", "+vertex.y+")");
}
}
I have taken some of the code out to simplify things (will add back in later) however I'm unsure if I am interpeting this problem right becasue after moveing the rectangle away from the origin, the rest of these steps don't make sense. I'd appreciate any helpful input.;)
Thanks,
Alice