Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

( In JAVA)Define a class named Rectangle. A Rectangle object stores an (x, y) coordinate of its top/left corner, a width, and a height. Each

( In JAVA)Define a class named Rectangle. A Rectangle object stores an (x, y) coordinate of its top/left corner, a width, and a height.

Each Rectangle object should have the following public methods:

Rectangle(x, y, width, height) Constructs a new rectangle whose top-left corner is specified by the given coordinates and with the given width and height.

getX() Returns this rectangle's leftmost x-coordinate.

getY() Returns this rectangle's top y-coordinate.

getWidth() Returns this rectangle's width.

getHeight() Returns this rectangle's height.

toString() Returns a String representation of this rectangle, such as "Rectangle[x=1,y=2,width=3,height=4]".

contains(x, y) Returns whether the given Point's coordinates lie inside the bounds of this rectangle.

intersect(rect) Turns this rectangle into the intersection of itself and the given other rectangle rect; that is, the largest rectangular region completely contained within both this rectangle and the given other rectangle. (In the picture at right, the intersection of the two rectagles is the shaded black region.) You may assume that the two rectangles do overlap and therefore have a nonempty intersection.

equals(o) Returns whether the given other object o is a rectangle with the same x/y coordinates, width, and height as this rectangle. You may assume that o refers to a Rectangle object.

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Next Generation Databases NoSQLand Big Data

Authors: Guy Harrison

1st Edition

1484213300, 978-1484213308

More Books

Students also viewed these Databases questions