What I have here is the skeleton of the project in Java. This is based off of creating data types and I will basically have it find the area, perimeter, find if they intersect or contain each other. I understand the formulas I need to use but how would I actually create rectangle b so just like the initial rectangle I have to have an x,y center and a width and height? I had tried in a similar fashion to declare rectangle b but it refuses to assign any of the variables.
In order to find if it rectangle b intersects with the other rectangle I need to define it in order to do calculations for the corners of the rectangle etc, here is my code:
public class OwnRectangles {
private final double x,y; //center of rectangle
private final double width; //width of rectangle
private final double height; //height of rectangle
public Rectangle(double x0, double y0, double w, double h)
{
x=x0;
y=y0;
width=w;
height=h;
}
public double area()
{
return width*height;
}
public double perimeter()
{
return height*2 + width*2;
}
public boolean intersects(Rectangle b)
{
}
public boolean contains(Rectangle b)
{
}
public void draw(Rectangle b)
{
/*Draw rectangle on standard drawing*/
}
}
I essentially am trying to create another rectangle, I tried something like this which would not work:
public OwnRectanglesb(double x2, double y2, double w2, double h2)
{
x=x2;
y=y2;
width=w2;
height=h2;
}
Not only does this name not match the OwnRectangles b, but the public... is supposed to be just OwnRectangles if that makes sense. Very simply I want to define a second rectangle to use.
OwnRectanglesthe constructor should have the same name; b) last two methods are missing return statements (so it won't compile); c) what do you mean by "it refuses to assign any of the variables"?double x0, double y0, double w, double h" - Please don't do that. Give the parameters some meaningful names.