Question: from my java and algorithm classes Programming Project: 4.47: Add the concept of a position to the Shape hierarchy by including coordinates as data members.

from my java and algorithm classes

Programming Project:

4.47: Add the concept of a position to the Shape hierarchy by including coordinates as data members. Then add a distance method.

I assume that adding a distance method means a general purpose - static - method in the Shape class that takes 2 Shapes and returns a double value. I have added this method into the code above for you.

There are many ways to pass in the x and y coordinates to the shape. We could change all the constructors to include these two new variables, for example. However, to make it easier for me to create a grader file, I have added the putShapeHere method into the Shape class as the way someone would position a shape in a two dimensional environment.

this is the code where i need to work on

public class Rectangle extends Shape {

private double length;

private double width;

public Rectangle( double len, double wid ) {

length = len; width = wid;

}

public double area( ) {

return length * width;

}

public double perimeter( ) {

return 2 * ( length + width );

}

public String toString( ) {

return "Rectangle: " + length + " " + width;

}

public double getLength( ) {

return length;

}

public double getWidth( ) {

return width;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!