Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement classes rectangle and Circle inherit from the abstract class Shape. pu

ID: 3655236 • Letter: I

Question

Implement classes rectangle and Circle inherit from the abstract class Shape.

public abstract class Shape {

// Usage: p = s.getCenter()

// before: nothing

//after: p is the middle of s

public abstract Point2D getCenter();

// usage: r = s.getBoundingBox()

// before: nothing

//after: r is the smallest rectangle that fits around the s

public abstract Rectangle getBoundingBox();

// useage: c = s.intersects(o)

// before: nothing

// after: c is true of s and o overlaps

public abstract boolean intersects(Shape o);

// useage: s.scale(f)

// before: f > 0

// after: s is f-times bigger and the middle is the same

public abstract void scale(double f); }

Add a rectangle clusters methods getWidth, getHeight, setWidth and seth eight and describe them. Add to Circle as the cluster method getRadius.

If the class Square would inherit from rectangle, how would pre-condition data look for that class? What methods would break pre-condition data or reasoned programming this class? How would your answer change if clusters were unchanged If the class Square would inherit from rectangle, how would pre-condition data look for that class? What methods would break pre-condition data or reasoned programming this class? How would your answer change if clusters were unchanged.

Explanation / Answer

abstract class Rectangle extends Shape{ double height; double width; public double getHeight() { return height; } public void setHeight(double height) { this.height = height; } public double getWidth() { return width; } public void setWidth(double width) { this.width = width; } } abstract class Circle extends Shape{ double radius; public double getRadius() { return radius; } } if square is inherit from rectangle then it is of abstract type.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote