## Description

In this programming assignment, you will create classes that model 2D geometric shapes: Rectangle2D, and Line2D.

These shapes share an abstract base class Shape2D that defines a common set of methods. The child classes also have their own methods that are appropriate for the shapes, and store their data in different ways. Rectange2D and Circle2D are defined by a bounding box with a top-left x and y, and a width and height. Line2D is defined by its two end points.

To understand the differences in how C++ and Java represent class hierarchies, you will implement these classes in both C++ and Java. Here are descriptons of the classes and the methods that they implement.

## Java Version

Define these classes in the package edu.northeasstern.cs_5004. Provide a unit test and main program in the class TestShapes in the file “TestShapes.java”. Use your Java implementation of Point2D from programming assignment 2.

interface Shape2D

Define the interface Shape2D in a file “Shape2D.java”

Note: Java does not require adding a “forward reference” to class Rectangle2D before defining Point2D. Java is able to handle this kind of “circular reference.”

Method name Type Parameters Description

getBounds Rectangle2D none Returns the bounding box for the shape

setBounds none float x, float y, float width, float height Sets the bounding box for the shape with top-left point (x, y), and dimensions (width, height)

setBounds none Point2D topLeft, float width, float height Sets the bounding box for the shape with top-left point (x, y), and dimensions (width, height)

setBounds none Rectangle2D bounds Sets the bounding box for the shape

containsPoint boolean Point2D point Determines whether shape contains the point

class Rectangle2D implements Shape2D

Define the class Rectangle2D in a file “Rectangule2D.java”. All constructors and methods are public.

Hint: The constructors can call setBounds().

Field name Type Description

private x float the X coordinate of the top left of the rectangle

private y float the Y coordinate of the top left point of the rectangle

private width float the width of the rectangle

private height float the height of the rectangle

Method name Type Parameters Description

Rectangle2D none none Constructs a rectangle at (0, 0) with dimensions (0, 0)

Rectangle2D none float x, float y, float width, float height Constructs a rectangle with top-left point (x, y), and dimensions (width, height)

Rectangle2D none Point2D topLeft, float width, float height Constructs a rectangle with top-left point, and dimensions (width, height)

Rectangle2D none Rectangle2D rect Constructs a rectangle with location and dimensions of a rectangle

getX float none Returns the X of the top left corner of the rectangle

getY float none Returns the Y of the top left corner of the rectangle

getWidth float none Returns the width of the rectangle

getHeight float none Returns the height of the rectangle

getBounds (@Override) Rectangle2D none Returns the bounding box for the rectangle

setBounds (@Override) none float x, float y, float width, float height Sets the bounding box for the rectangle with top-left point (x, y), and dimensions (width, height)

setBounds (@Override) none Point2D topLeft, float width, float height Sets the bounding box for the rectangle with top-left point (x, y), and dimensions (width, height)

setBounds (@Override) none Rectangle2D bounds Sets the bounding box for the rectangle

containsPoint (@Override) bool Point2D point Determines whether shape contains the point

class Circle2D implements Shape2D

Define the class Circle2D in a file “Circle2D.java”. All constructors and methods are public.

Hint: The constructors can call setBounds().

Field name Type Description

private x float the X coordinate of the top left of the circle

private y float the Y coordinate of the top left point of the circle

private width float the width of the circle

private height float the height of the circle

Method name Type Parameters Description

Circle2D none none Constructs a circle at (0, 0) with dimensions (0, 0)

Circle2D none float x, float y, float width, float height Constructs a circle with top-left point (x, y), and dimensions (width, height)

Circle2D none Point2D topLeft, float width, float height Constructs a circle with top-left point, and dimensions (width, height)

Circle2D none Circle2D circle Constructs a circle with location and dimensions of a rectangle

getX float none Returns the X of the top left corner of the circle

getY float none Returns the Y of the top left corner of the circle

getWidth float none Returns the width of the circle

getHeight float none Returns the height of the circle

getBounds (@Override) Rectangle2D none Returns the bounding box for the circle

setBounds (@Override) none float x, float y, float width, float height Sets the bounding box for the circle with top-left point (x, y), and dimensions (width, height)

setBounds (@Override) none Point2D topLeft, float width, float height Sets the bounding box for the circle with top-left point (x, y), and dimensions (width, height)

setBounds (@Override) none Rectangle2D bounds Sets the bounding box for the circle

containsPoint (@Override) bool Point2D point Determines whether shape contains the point

class Line2D implements Shape2D

Define this concrete class Line2D in a file “Line2D.java”. All constructors and methods are public.

Field name Type Description

private x1 float the X coordinate of the first point of the line

private y1 float the Y coordinate of the first point of the line

private x2 float the X coordinate of the last point of the line

private y2 float the Y coordinate of the last point of the line

Method name Type Parameters Description

Line2D none none Constructs a line with points (0, 0), (0, 0)

Line2D none Point2D point1, Point2D point2 Constructs a line with points point1, point2

Line2D none float x1, float y1, float x2, float y2 Constructs a line with points (x1, y1), (x2, y2)

Line2D none Line2D line Constructs a line with points of a line

getPoint1 Point2D none Returns the first point of the line

getPoint2 Point2D none Returns the second point of the line

getBounds (@Override) Rectangle2D none Returns the bounding box for the shape

setBounds (@Override) none Rectangle2D bounds Sets the bounding box for the line, keeping the relative positions of the two points.

setBounds (@Override) none float x, float y, float width, float height Sets the bounding box for the line with top-left point (x, y), and dimensions (width, height), keeping the relative positions of the two points.

setBounds (@Override) none Point2D topLeft, float width, float height Sets the bounding box for the line with top-left point (x, y), and dimensions (width, height)

containsPoint (@Override) boolean Point2D point Determines whether line contains the point