Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions